Skip to content

Commit

Permalink
Omsi globals (#41)
Browse files Browse the repository at this point in the history
* + Inital Move to dedicated Globals Class

* + Add to base plugin

* + Base TTMan

* + Add to base plugin

* Accidents happen -
Revert " + Add to base plugin"

This reverts commit 5a526f7.

* + Add to globals

* ! DEPRECATION ! - All globals are being moved to the Globals property.

 + Added Obsolete attributes
 + Added OmsiTTLogDetailed to globals

* + Correct docs

* + docs

* + Resolve many of the noted issues

* + Make it a pointer

* + Make is compileable

* + Add to readme

* I still can't spell

Co-authored-by: Thomas Mathieson <[email protected]>
  • Loading branch information
amathieson and space928 authored May 9, 2022
1 parent 3bfed41 commit c2c9529
Show file tree
Hide file tree
Showing 9 changed files with 515 additions and 16 deletions.
24 changes: 12 additions & 12 deletions OmsiExtensionsCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ static void Main(string[] args)

while (true)
{
var pos = omsi.PlayerVehicle.Position;
var posa = omsi.PlayerVehicle.AbsPosition;
var vel = omsi.PlayerVehicle.Velocity;
var map = omsi.Map;
var weather = omsi.Weather;
var tickets = omsi.TicketPack;
var humans = omsi.Humans;
var pos = omsi.Globals.PlayerVehicle.Position;
var posa = omsi.Globals.PlayerVehicle.AbsPosition;
var vel = omsi.Globals.PlayerVehicle.Velocity;
var map = omsi.Globals.Map;
var weather = omsi.Globals.Weather;
var tickets = omsi.Globals.TicketPack;
var humans = omsi.Globals.Humans;

Console.SetCursorPosition(0, 0);
Console.WriteLine(($"Read data: x:{pos.x:F3} y:{pos.y:F3} z:{pos.z:F3} " +
$"tile:{omsi.PlayerVehicle.Kachel}").PadRight(Console.WindowWidth - 1));
$"tile:{omsi.Globals.PlayerVehicle.Kachel}").PadRight(Console.WindowWidth - 1));
Console.WriteLine($"Read data: vx:{vel.x:F3} vy:{vel.y:F3} vz:{vel.z:F3}".PadRight(Console.WindowWidth-1));
Console.WriteLine($"Read data: ax:{posa._30:F3} ay:{posa._31:F3} az:{posa._32:F3}".PadRight(Console.WindowWidth-1));

Console.WriteLine($"Read data: map:{map.Name} path:{map.Filename} friendly:{map.FriendlyName}".PadRight(Console.WindowWidth-1));
Console.WriteLine($"{omsi.PlayerVehicle.PAI_LastBrake} {omsi.PlayerVehicle.Bremspedal}".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"{omsi.Time.Day}/{omsi.Time.Month}/{omsi.Time.Year} - {omsi.Time.Hour}:{omsi.Time.Minute}:{omsi.Time.Second:F2}");
Console.WriteLine($"{omsi.Globals.PlayerVehicle.PAI_LastBrake} {omsi.Globals.PlayerVehicle.Bremspedal}".PadRight(Console.WindowWidth - 1));
Console.WriteLine($"{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("".PadRight(Console.WindowWidth-1));
//omsi.PlayerVehicle.Velocity = new D3DVector { x=0, y=0, z=5 };
//omsi.PlayerVehicle.Bremspedal = 0;
//omsi.Globals.PlayerVehicle.Velocity = new D3DVector { x=0, y=0, z=5 };
//omsi.Globals.PlayerVehicle.Bremspedal = 0;

Thread.Sleep(50);
}
Expand Down
75 changes: 75 additions & 0 deletions OmsiHook/OmsiGlobals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OmsiHook
{
/// <summary>
/// All recoginised Globals in OMSI
/// </summary>
public class OmsiGlobals : OmsiObject
{
internal OmsiGlobals(Memory omsiMemory, int baseAddress, OmsiHook hook) : base(omsiMemory, baseAddress) { this.hook = hook; }
public OmsiGlobals(OmsiHook hook) : base() { this.hook = hook; }

private OmsiRemoteMethods remoteMethods;
private OmsiHook hook;

/// <summary>
/// Gets the vehicle instance being driven by the player.
/// </summary>
public OmsiRoadVehicleInst PlayerVehicle => hook.GetRoadVehicleInst(PlayerVehicleIndex);
public int PlayerVehicleIndex => Memory.ReadMemory<int>(0x00861740);

/// <summary>
/// Current Weather
/// </summary>
public OmsiWeather Weather => new(Memory, Memory.ReadMemory<int>(0x008617D0));

/// <summary>
/// Current Map
/// </summary>
public OmsiMap Map => new(Memory, Memory.ReadMemory<int>(0x861588));

/// <summary>
/// In game TicketPack List
/// </summary>
public OmsiTicketPack TicketPack => Memory.MarshalStruct<OmsiTicketPack, OmsiTicketPackInternal>(
Memory.ReadMemory<OmsiTicketPackInternal>(0x008611fc));

/// <summary>
/// Access to RemoteMethods
/// </summary>
public OmsiRemoteMethods RemoteMethods => remoteMethods ??= new(Memory, 0);

/// <summary>
/// Current in game Date / Time
/// </summary>
public OmsiTime Time => new(Memory, 0);

/// <summary>
/// In game Driver List
/// </summary>
public OmsiDriver[] Drivers => Memory.MarshalStructs<OmsiDriver, OmsiDriverInternal>(Memory.ReadMemoryStructArray<OmsiDriverInternal>(0x008614F8));
public int SelectedDriver => Memory.ReadMemory<int>(0x008614FC);

/// <summary>
/// Current Service logs
/// </summary>
public OmsiTTLogDetailed[] OmsiTTLogs => Memory.MarshalStructs<OmsiTTLogDetailed, OmsiTTLogDetailedInternal>(
Memory.ReadMemoryStructArray<OmsiTTLogDetailedInternal>(0x00861750));

/// <summary>
/// Current real weather config
/// </summary>
public OmsiActuWeather ActuWeather => new(Memory, Memory.ReadMemory<int>(0x00861278));
public OmsiHumanBeingInst[] Humans => Memory.ReadMemoryObjArray<OmsiHumanBeingInst>(0x0086172c);

/// <summary>
/// Timetable manager for current session
/// </summary>
public OmsiTimeTableMan TimeTableManager => new(Memory, Memory.ReadMemory<int>(0x008614e8));
}
}
16 changes: 16 additions & 0 deletions OmsiHook/OmsiHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,72 @@ public class OmsiHook
{
private Memory omsiMemory;
private Process process;
private OmsiGlobals globals;
private OmsiRemoteMethods remoteMethods;

public OmsiGlobals Globals => globals ??= new(omsiMemory, 0, this);


/// <summary>
/// Gets the vehicle instance being driven by the player.
/// </summary>
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiRoadVehicleInst PlayerVehicle => GetRoadVehicleInst(PlayerVehicleIndex);
[Obsolete("This property has been moved to the Globals Property.")]
public int PlayerVehicleIndex => omsiMemory.ReadMemory<int>(0x00861740);

/// <summary>
/// Current Weather
/// </summary>
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiWeather Weather => new(omsiMemory, omsiMemory.ReadMemory<int>(0x008617D0));

/// <summary>
/// Current Map
/// </summary>
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiMap Map => new(omsiMemory, omsiMemory.ReadMemory<int>(0x861588));

/// <summary>
/// In game TicketPack List
/// </summary>
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiTicketPack TicketPack => omsiMemory.MarshalStruct<OmsiTicketPack, OmsiTicketPackInternal>(
omsiMemory.ReadMemory<OmsiTicketPackInternal>(0x008611fc));

/// <summary>
/// Access to RemoteMethods
/// </summary>
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiRemoteMethods RemoteMethods => remoteMethods ??= new(omsiMemory, 0);

/// <summary>
/// Current in game Date / Time
/// </summary>
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiTime Time => new(omsiMemory, 0);

/// <summary>
/// In game Driver List
/// </summary>
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiDriver[] Drivers => omsiMemory.MarshalStructs<OmsiDriver, OmsiDriverInternal>(omsiMemory.ReadMemoryStructArray<OmsiDriverInternal>(0x008614F8));
[Obsolete("This property has been moved to the Globals Property.")]
public int SelectedDriver => omsiMemory.ReadMemory<int>(0x008614FC);

/// <summary>
/// Current Service logs
/// </summary>
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiTTLogDetailed[] OmsiTTLogs => omsiMemory.MarshalStructs<OmsiTTLogDetailed, OmsiTTLogDetailedInternal>(
omsiMemory.ReadMemoryStructArray<OmsiTTLogDetailedInternal>(0x00861750));

/// <summary>
/// Current real weather config
/// </summary>
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiActuWeather ActuWeather => new(omsiMemory, omsiMemory.ReadMemory<int>(0x00861278));
[Obsolete("This property has been moved to the Globals Property.")]
public OmsiHumanBeingInst[] Humans => omsiMemory.ReadMemoryObjArray<OmsiHumanBeingInst>(0x0086172c);

/// <summary>
Expand Down
Loading

0 comments on commit c2c9529

Please sign in to comment.