Coder Social home page Coder Social logo

Comments (11)

 avatar commented on May 30, 2024

Just a minor note: Please keep in mind that support for 64 bit / DirectX 11 isn't available yet since we are working on collecting the data for it.

To the topic at hand: this error usually occured to me when attempting to access something although the library is not fully loaded / setup. In the very first version of my scanner thread I ended up using something like this:

while (true) {
	var readResult = Reader.GetActors();
	if (readResult != null && readResult.NewPC.Any()) {
		try {
			Console.WriteLine(readResult.PCEntities.FirstOrDefault().Value.CurrentUser.Name);
		} catch(Exception _) {
			Console.WriteLine("Fail.");
		}
	}
	Thread.Sleep(100);
}

You error most likely occurs while doing something like this:

ActorReadResult readResult = Reader.GetActors();
return readResult.PCEntities.FirstOrDefault().Value.CurrentUser;

The readResult will be successfully populated if the lib is fully initialized, otherwise it is null thus the second line throws a NullPointerException in the underlying structures. A very naive approach to possibly fix this, similiar to @viion, is to Thread.Sleep after InitiateMemory for ~2 seconds. To make it more robust though, add some null pointer checks then you can find out when you are starting to see proper data.

from sharlayan.

roxaskeyheart avatar roxaskeyheart commented on May 30, 2024

Oh thanks for letting me know about the DX11 stuff. Good to keep in mind.

As for the other issue, I'm getting this error just by running the above code snippet and not even trying to fetch any of the data. :/

Would you have any suggestions regarding that?

from sharlayan.

 avatar commented on May 30, 2024

Can you quickly check whether there is a file called enums-x86.json inside your output directory? The library downloads the enumerations from the API and then loads them - maybe something is wrong during this process. I am quickly setting up a test solution to try this myself, since I am no longer using the original library and wrote a lighter version for my project.

from sharlayan.

roxaskeyheart avatar roxaskeyheart commented on May 30, 2024

Oh i don't think there is any json files in the output directory when I built from the source or used the dll found in the distribution folder. Should i make a blank file?

from sharlayan.

 avatar commented on May 30, 2024

How have you included the library? It has some NuGet data attached since it uses Newtonsoft.Json for reading and parsing the files. This is my code and my project structure:

Project Structure

And this is the output folder (running dll and my app on x86 build config for this case):

Folder Structure

If you don't have the DLL included in your solution, I suggested doing that instead of referencing the plain DLL just to be sure that the NuGet commands propagate to your project as well.

from sharlayan.

roxaskeyheart avatar roxaskeyheart commented on May 30, 2024

When you say included, does that mean adding it as a reference or using NuGet to add it? Sorry i was a little confused >.<

I've just been adding it using references before now.

from sharlayan.

 avatar commented on May 30, 2024

Try to create a completely new solution for testing and clone the ffxivapp-memory repository. In your solution you should then have a testing application and the cloned repository added like me. This makes sure that the dependencies are registered to the solution for the build process. If you are then able to run my code from the screenshot with the same setup you're good to go to add the repository to your project as well.

from sharlayan.

roxaskeyheart avatar roxaskeyheart commented on May 30, 2024

Okay I think I worked out what the issue is, my code for DX11 was still being called and that code is what causes that exception to throw. When the DX9 initialisation is called it seems to work alright. 👍

On a quick side note, how would I go about fetching the current player's HP, MP and TP data? I know GetPlayerInfo() has MaxHP, MaxMP and MaxTP values but not the current values.

from sharlayan.

 avatar commented on May 30, 2024

Alright, the DX11 part has no data anyways, thus no enums are downloaded and you get the NullPointerException.

For reading data you shoul not use GetPlayerInfo since this returns you data from the character sheet like Strength, Dexterity, Skill Speed etc. Refer to the code that @viion is using and that he has posted here. Remember to slightly change the getPlayer method to check for null like I did in my previous comments. The function will then return an ActorEntity which stores all information about the player entity.

from sharlayan.

roxaskeyheart avatar roxaskeyheart commented on May 30, 2024

Awesome thank you so much. ^^

from sharlayan.

Icehunter avatar Icehunter commented on May 30, 2024

Thank you @ChristianIvicevic for following up on this. @roxaskeyheart Another thing you can do as well to ensure you don't get null reference exceptions is use https://davefancher.com/2014/08/14/c-6-0-null-propagation-operator/.

Example:

var name = readResult?.PCEntities?.FirstOrDefault()?.Value?.CurrentUser?.Name
if (!string.IsNullOrEmptyOrWhiteSpace(name)) {
  // do stuff
}

With this it won't throw an error and you have access to the property

from sharlayan.

Related Issues (20)

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.