Coder Social home page Coder Social logo

scottlync / insimdotnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexmcbride/insimdotnet

0.0 0.0 0.0 1.2 MB

.NET InSim library for the racing simulator Live for Speed.

Home Page: https://www.lfs.net/forum/thread/68564--NET---InSim-NET---InSim-library

License: GNU Lesser General Public License v2.1

Smalltalk 0.62% C# 99.38%

insimdotnet's Introduction

InSim.NET

For a .NET Core version of the library go here. For a .NET 6 version of the library go here.

InSim.NET is a .NET InSim library for the online racing simulator Live for Speed. It allows you to connect to the game and share packets of data. These packets can be used to control Live for Speed, send commands, handle requests and receive car telemetry data.

The library has been designed to be simple, fast and flexible, and stays as close to the original InSim protocol as possible, while saving you from the nitty-gritty of socket programming directly.

This project site is for version 2.0 of the library, which includes full InSim, InSim Relay, OutSim and OutGauge support, improvements to the API and improved network efficiency.

From InSim.NET 2.1.0 onwards the library requires .NET Framework 4.5. Older binaries for .NET 4.0 and 3.5 are available in the releases section.

To install InSimDotNet using NuGet run the following command in the Package Manager Console.

PM> Install-Package InSimDotNet

Donate

You can now donate using PayPal to help fund the development of InSim.NET. Any amount is welcome! Just click the image below.

alt Donate

InSim

This is the simplest InSim program you can write (that does something). We initialize InSim and send the message 'Hello, InSim!' to the game's chat.

InSim insim = new InSim();

// Initialize InSim
insim.Initialize(new InSimSettings {
    Host = "127.0.0.1",
    Port = 29999,
    Admin = String.Empty,
});

// Send message to LFS
insim.Send("/msg Hello, InSim!");

To receive a packet bind a handler using the InSim.Bind() method. In this example we bind a handler for the IS_MSO (MeSsage Out) packet event.

void RunInSim() {
    InSim insim = new InSim();

    // Bind MSO packet event.
    insim.Bind<IS_MSO>(MessageOut);

    // Initialize InSim
    insim.Initialize(new InSimSettings {
        Host = "127.0.0.1",
        Port = 29999,
        Admin = String.Empty,
    });
}

// Method called when MSO packet is recieved
void MessageOut(InSim insim, IS_MSO packet) {
    // Print contents of MSO message to the console.
    Console.WriteLine(packet.Msg);
}

To send a packet use the InSim.Send(ISendable) method.

insim.Send(new IS_TINY {
    SubT = TinyType.TINY_NCN
});

To save bandwidth send multiple packets in a single call using the InSim.Send(params ISendable[]) method.

insim.Send(
    new IS_TINY {
        SubT = TinyType.TINY_NCN
    },
    new IS_SMALL {
        SubT = SmallType.SMALL_SSP,
    }
);

To keep a program open while InSim is still connected.

while (insim.IsConnected) {
    Thread.Sleep(200);
}

Here is it all together.

void RunInSim() {
    InSim insim = new InSim();

    // Bind packet events.
    insim.Bind<IS_NCN>(NewConnection);
    insim.Bind<IS_NPL>(NewPlayer);

    // Initialize InSim
    insim.Initialize(new InSimSettings {
        Host = "127.0.0.1",
        Port = 29999,
        Admin = String.Empty,
    });
    
    // Request all connections and players to be sent.
    insim.Send(new [] {
        new IS_TINY { SubT = TinyType.TINY_NCN },
        new IS_TINY { SubT = TinyType.TINY_NPL },
    });
    
    // Stop console app from exiting while connection is active.
    while (insim.IsConnected) {
        Thread.Sleep(200);
    }
}

// Method called when NCN packet is recieved
void NewConnection(InSim insim, IS_NCN packet) {
    // Handle new connection.
}

// Method called when NPL packet is recieved
void NewPlayer(InSim insim, IS_NPL packet) {
    // Handle new player.
}

InSim Relay

To use InSim Relay it's a matter of setting the InSimSettings.IsRelayHost property to true.

InSim insim = new InSim();

// Initialize InSim relay
insim.Initialize(new InSimSettings {
    IsRelayHost = true,
});

// Send host select packet
insim.Send(new IR_SEL { HName = "<insert host name>" });

OutGauge & OutSim

Using OutGauge (or OutSim) is just as simple! This example prints the currently viewed car's RPM to the console.

OutGauge outgauge = new OutGauge();

// Attach OutGauge packet event
outgauge.PacketReceived += (sender, e) => {
    Console.WriteLine(e.RPM);
};

// Start listening for packets
outgauge.Connect("127.0.0.1", 30000);

You can find many more examples and information about using the library in the documentation wiki.

insimdotnet's People

Contributors

alexmcbride avatar vitinh0w avatar xspeedasx avatar retr0mrwave avatar mkapal avatar neonsp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.