Giter Site home page Giter Site logo

roxeez / moonlight Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 5.0 6.36 MB

Moonlight is made for easily create .NET application for NosTale using an easy to use API.

License: GNU General Public License v3.0

C# 100.00%
nostale nostale-clientless nostale-crypto api moonlight dll bot injection

moonlight's Introduction

Moonlight

Moonlight aims to make NosTale .NET Application developer life easier by giving them access to a complete & easy to use API allowing them to interact with (almost) everything in the game
Moonlight can be used with local client (injected .dll) or remote client (clientless)

Codacy grade AppVeyor AppVeyor tests GitHub commit activity GitHub

Getting Started

  • Create a C# .dll project targeting .NET Framework 4.7+
  • Add Moonlight as submodule
  • Install DllExport to your project and create your export function (cf. DllExport wiki)
  • Build your project
  • Create database.db using Moonlight.Toolkit CLI
  • Copy previously generated database.db to a subfolder named Moonlight in your NosTale folder
  • Copy your generated .dll & MoonlightCore to your NosTale folder
  • Inject your .dll using an injector supporting custom export function.

Moonlight is a packet based lib, so if you want everything to work correctly using local client, it should be injected before character selection.

Example

Example application can be found here : https://github.com/Roxeez/Moonlight.Example

private async Task BotLoop()
{
    while (IsRunning)
    {
        IEnumerable<Monster> monsters;
        Skill zoneSkill;
        do
        {
            zoneSkill = Configuration.UsedSkills.FirstOrDefault(x => !x.IsOnCooldown);
            monsters = Client.Character.Map.Monsters
                .Where(x => x.Vnum == MonsterConstants.SoftPii)
                .Where(x => x.Position.IsInRange(Client.Character.Position, Radius))
                .OrderBy(x => x.Position.GetDistance(Client.Character.Position));
            
            Monster closestPod = await GetClosestPod();
            if (closestPod == null)
            {
                return;
            }

            await Client.Character.Attack(closestPod);
        } 
        while ((monsters.Count() < 10 || zoneSkill == null) && IsRunning);

        if (monsters.Count() < 10)
        {
            return;
        }
        
        await Client.Character.UseSkillOn(zoneSkill, monsters.First());
        await Task.Delay(100);
    }
}

private async Task<Monster> GetClosestPod()
{
    Monster pod;
    do
    {
        pod = Client.Character.Map.Monsters
            .Where(x => x.Vnum == MonsterConstants.SoftPiiPod)
            .Where(x => x.Position.IsInRange(Client.Character.Position, Radius))
            .OrderBy(x => x.Position.GetDistance(Client.Character.Position))
            .FirstOrDefault();
        
        await Task.Delay(100);
    } 
    while (pod == null && IsRunning);

    return pod;
}

Prerequisites

  • .NET Framework 4.7

Contributors

  • Roxeez

Special thanks

  • Pumba98 for helping me with some C++/RE related stuff

License

This project is licensed under the GPL-3.0 License - see the LICENSE.md file for details

moonlight's People

Contributors

roxeez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

moonlight's Issues

HPPercent not updating

Hello

I am getting all Monsters of a map with sender.Map.Monsters. But when i check the HP, it always stays the same, even when I attack or kill the monster. Is there a way to check the live status?

And would it be possible to target or select a monster? I think its a little suspicious if i kill a monster before selecting ( sending ncif to the server).

Greetings

Removal of character from map on death (su packet)

If entity dies, it gets removed from the map. This is fine for most of the cases. For mobs the mob just disappears, for players you will get the new info on respawn.

Problem comes with Character, if I die, I won't get my info again. The entity is not in the Map and it will come back only when going to another map and back. This can be a problem, because new packets won't be handled correctly. The entity will always be null (at least for su packet)

The responsible method for this is SuPacketHandler::Handle. It calls map.RemoveEntity(target);

I hotfixed it using

if (target.Id != client.Character.Id)
{
    map.RemoveEntity(target);
}

I didn't test it for any side effects.

Too much encapsulation IMO

Hey, I think that your library contains too much encapsulation.

Namely I mean the EventManager, PacketHandlerManager, services in MoonlightAPI.
This makes it pain to do things like adding new external packets - this would come in handy, because you don't support all the packets and I had to make a fork of your project to add some.
I wouldn't see a problem in making these classes public and also exposing Services in MoonlightAPI.

I forked your project and somehow exposed the services. You can check it out here: https://github.com/Rutherther/Moonlight/blob/master/srcs/Moonlight/MoonlightAPI.cs#L52
It probably could be done better, but in general I think that you should pass in a class containing initialization method.

Another thing I wanted to make is a "packet simulator". I didn't want to test my program in NosTale every time I made a change (I am working on a damage indicator). I made a MockClient, it just calls PacketHandlerManager::Handle on Receiving or Sending packets and that way I can load a file and test it on that. This is impossible with the current level of encapsulation - again PacketHandlerManager have to be public plus you have to expose the services provider.

Is there any specific reason why you have made these classes internal? I simply don't see any reason for that. I like encapsulating things myself, but in my opinion, this is too much.

Add a method to walk towards a position until the character is within a certain radius

I was thinking about adding a method that lets your character walk towards a position until it's within a certain radius around it. For example, it'd be useful if you want to use a skill with a range higher than one cell (e.g. mage/archer base attack) instead of Walking to the monster position.
One way would be to add the following method to the Character class:

public async Task WalkUntilInRadius(Position destination, int radius)
{
    int distance = Position.GetDistance(destination);
    if (distance <= radius)
    {
        return;
    }

    double distRatio = (distance - radius) / (double)distance;
    double x = Position.X + distRatio * (destination.X - Position.X);
    double y = Position.Y + distRatio * (destination.Y - Position.Y);

    await Walk(new Position((short)x, (short)y));
}

Then, instead of doing this

if (monster.Position.GetDistance(character.Position) > skill.Info.Range)
{
    await character.Walk(monster.Position);
 }

you just need this

await character.WalkUntilInRadius(monster.Position, skill.Info.Range);

I don't know if I explained in a good way the purpose of the above method. In case I didn't, I'll leave here an image made with my pr0 design skills™ that should explain it.

Cheers!

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.