Skip to content

Commit

Permalink
Cleanup, hopefully make it compatible on 1.18 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
xirreal committed May 3, 2024
1 parent 15503de commit 95d75e8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
14 changes: 11 additions & 3 deletions src/main/java/dev/xirreal/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ public class Activity extends Structure {
public int type;
public String description;

public String getType() {
return switch (type) {
case ActivityType.NGFX_INJECTION_ACTIVITY_UNKNOWN -> "NGFX_INJECTION_ACTIVITY_UNKNOWN";
case ActivityType.NGFX_INJECTION_ACTIVITY_FRAME_DEBUGGER -> "NGFX_INJECTION_ACTIVITY_FRAME_DEBUGGER";
case ActivityType.NGFX_INJECTION_ACTIVITY_GENERATE_CPP_CAPTURE -> "NGFX_INJECTION_ACTIVITY_GENERATE_CPP_CAPTURE";
case ActivityType.NGFX_INJECTION_ACTIVITY_GPU_TRACE -> "NGFX_INJECTION_ACTIVITY_GPU_TRACE";
case ActivityType.NGFX_INJECTION_ACTIVITY_PYLON_CAPTURE -> "NGFX_INJECTION_ACTIVITY_PYLON_CAPTURE";
default -> "Unknown Activity";
};
}

public static interface ActivityType {
public interface ActivityType {
int NGFX_INJECTION_ACTIVITY_UNKNOWN = 0;

int NGFX_INJECTION_ACTIVITY_FRAME_DEBUGGER = 1;
int NGFX_INJECTION_ACTIVITY_GENERATE_CPP_CAPTURE = 3;
int NGFX_INJECTION_ACTIVITY_GPU_TRACE = 4;
int NGFX_INJECTION_ACTIVITY_PYLON_CAPTURE = 5;

}

@Override
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/dev/xirreal/Installation.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ public class Installation extends Structure {
public short versionPatch;
public String installationPath;

public static String getSKU(Installation installation) {
return switch (installation.sku) {
case 0 -> "NGFX_NSIGHT_SKU_UNKNOWN";
case 1 -> "NGFX_NSIGHT_SKU_PUBLIC";
case 2 -> "NGFX_NSIGHT_SKU_PRO";
case 3 -> "NGFX_NSIGHT_SKU_INTERNAL";
default -> "Unknown";
public String getSku() {
return switch (sku) {
case SkuType.NGFX_NSIGHT_SKU_UNKNOWN -> "NGFX_NSIGHT_SKU_UNKNOWN";
case SkuType.NGFX_NSIGHT_SKU_PUBLIC -> "NGFX_NSIGHT_SKU_PUBLIC";
case SkuType.NGFX_NSIGHT_SKU_PRO -> "NGFX_NSIGHT_SKU_PRO";
case SkuType.NGFX_NSIGHT_SKU_INTERNAL -> "NGFX_NSIGHT_SKU_INTERNAL";
default -> "Unknown SKU";
};
}

public interface SkuType {
int NGFX_NSIGHT_SKU_UNKNOWN = 0;
int NGFX_NSIGHT_SKU_PUBLIC = 1;
int NGFX_NSIGHT_SKU_PRO = 2;
int NGFX_NSIGHT_SKU_INTERNAL = 3;
}

@Override
protected List<String> getFieldOrder() {
return Arrays.asList("sku", "versionMajor", "versionMinor", "versionPatch", "installationPath");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/xirreal/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void onInitialize() {
LOGGER.error("Frame debugger is not available for this installation");
return;
}

LOGGER.info("Found activity " + activity.getType() + ": "+ activity.description);
Result result = ngfx.Inject(newestInstallation, activity);
LOGGER.info("Injection result: " + result);
} catch (Exception e) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/dev/xirreal/NGFX.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package dev.xirreal;

import com.sun.jna.Native;
import com.sun.jna.Structure;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class NGFX implements NativeNGFX {
private final NativeNGFX _native;

public NGFX(final String dllPath) throws IOException {
if(!new java.io.File(dllPath).exists()) {
if(!new File(dllPath).exists()) {
throw new IOException("DLL not found: " + dllPath);
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/dev/xirreal/NativeNGFX.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package dev.xirreal;

import com.sun.jna.Library;
import com.sun.jna.Structure;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;

public interface NativeNGFX extends Library {
public int NGFX_Injection_EnumerateInstallations(IntByReference pCount, Installation[] pInstallations);
public int NGFX_Injection_EnumerateActivities(Installation pInstallation, IntByReference pCount, Activity[] pActivities);
public int NGFX_Injection_InjectToProcess(Installation pInstallation, Activity pActivity);
int NGFX_Injection_EnumerateInstallations(IntByReference pCount, Installation[] pInstallations);
int NGFX_Injection_EnumerateActivities(Installation pInstallation, IntByReference pCount, Activity[] pActivities);
int NGFX_Injection_InjectToProcess(Installation pInstallation, Activity pActivity);
}
4 changes: 2 additions & 2 deletions src/main/java/dev/xirreal/Result.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.xirreal;

public class Result {
int code = 0;
String message = "";
int code;
String message;

public Result(int code) {
this.code = code;
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"contact": {
"sources": "https://github.com/xirreal/nsight-loader"
},
"license": "MIT",
"license": "MIT & NVIDIA license",
"icon": "assets/nsight-loader/icon.png",
"environment": "*",
"entrypoints": {
Expand All @@ -20,7 +20,7 @@
},
"depends": {
"fabricloader": ">=0.15.10",
"minecraft": "~1.20.4",
"java": ">=21"
"minecraft": "^1.18.2",
"java": ">=17"
}
}

0 comments on commit 95d75e8

Please sign in to comment.