diff --git a/.idea/misc.xml b/.idea/misc.xml index 9bde07d..7c9ac40 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,10 @@ + - + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index fe997ea..071f68e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { testImplementation("org.mockito.kotlin:mockito-kotlin:5.0.0") implementation("net.java.dev.jna:jna:latest.release") + implementation(kotlin("reflect")) } tasks.test { diff --git a/src/main/kotlin/game_logic/runescape/RSAgent.kt b/src/main/kotlin/game_logic/runescape/RSAgent.kt index 285ff7a..4c0287f 100644 --- a/src/main/kotlin/game_logic/runescape/RSAgent.kt +++ b/src/main/kotlin/game_logic/runescape/RSAgent.kt @@ -73,13 +73,6 @@ class RSAgent(override val automaton: Automaton = RobotAutomaton()) : RSOrchestr * - Clicks the default "Accept" hotkey to start crafting. * - Waits for the specified crafting duration plus random variance. * - * Usage example: - * - * ``` - * val params = StandingTaskParams(...) - * orchestrator.processAtBank(params) - * ``` - * * @param taskParams The [StandingTaskParams] configuring the task details like bank location, hotkeys, and durations. */ override fun processAtBank( @@ -118,12 +111,6 @@ class RSAgent(override val automaton: Automaton = RobotAutomaton()) : RSOrchestr * * - Waits for the randomized crafting duration. * - * Usage example: - * ``` - * val params = TravelTaskParams(...) - * orchestrator.processAtStationNearBank(params) - * ``` - * * @param taskParams The [TravelTaskParams] configuring the task details. */ override fun processAtStationNearBank( @@ -164,17 +151,6 @@ class RSAgent(override val automaton: Automaton = RobotAutomaton()) : RSOrchestr * * It then returns the current mouse position as a Point after a slight delay. * - * The delay allows the mouse to settle before sampling its position. - * - * Usage example: - * ``` - * // Get bank location from user mouse position - * val bankPoint = orchestrator.getBankPoint() - * // Left click the bank to open the interface - * orchestrator.automaton.mouseMove(bankPoint) - * orchestrator.automaton.mouseClick(InputEvent.BUTTON1_DOWN_MASK) - * ``` - * * @return The Point position of the mouse after user positions it. */ override fun getBankPoint(): Point { @@ -184,19 +160,10 @@ class RSAgent(override val automaton: Automaton = RobotAutomaton()) : RSOrchestr /** * Sleeps for a specified number of game ticks. * - * This method calculates the total sleep duration based on the number of ticks - * and the tick duration constant. It then sleeps for that amount plus a small - * latency padding. - * - * A random variance is also added to the sleep duration to add some less-robotic behavior. - * - * Usage example: - * ``` - * val ticks = 10 // Sleep for 10 game ticks - * orchestrator.sleepTicks(ticks) - * ``` + * A brief random variance is also added to the sleep duration to add some less-robotic behavior. * * @param n The number of game ticks to sleep for. + * @see TICK_DURATION_MS */ override fun sleepForNTicks(n: Long) { val latencyPadding = LATENCY_PADDING_MS diff --git a/src/main/kotlin/game_logic/runescape/RunescapeRoutines.kt b/src/main/kotlin/game_logic/runescape/RunescapeRoutines.kt index d102369..ad77ed0 100644 --- a/src/main/kotlin/game_logic/runescape/RunescapeRoutines.kt +++ b/src/main/kotlin/game_logic/runescape/RunescapeRoutines.kt @@ -245,27 +245,9 @@ object RunescapeRoutines { * * @param volume The number of inventory slots to process at the furnace. * - * The following 2 values are hard coded from my own personal setup + * The following 2 values are hard coded from my own personal computer * furnaceFromChest The Point location of the furnace from the bank chest. * chestFromFurnace The Point location of the bank chest from the furnace. - * - * Uses an Agent instance for banking and traveling. - * - * This handles the workflow of: - * - Withdrawing bars at bank chest - * - Walking to furnace and processing bars into items - * - Walking back to bank and depositing processed items - * - * The furnace and bank locations are passed in as specific Point locations. - * The agent handles the navigation and banking actions. - * - * Usage example: - * - * ``` - * Routines.processAtFurnaceNearBank(1500) - * ``` - * - * Before processing, the camera is reset to align points. */ fun processInventoryAtFurnace(volume: Int) { //these two points are specific to my computer. we need to export these into a file or something diff --git a/src/main/kotlin/native/HelloWorldWrapper.kt b/src/main/kotlin/native/HelloWorldWrapper.kt new file mode 100644 index 0000000..f131a10 --- /dev/null +++ b/src/main/kotlin/native/HelloWorldWrapper.kt @@ -0,0 +1,28 @@ +package native + +import com.sun.jna.Library +import com.sun.jna.Native +import com.sun.jna.NativeLong + + +interface HelloWorldWrapper: Library{ + companion object { + init{ + System.setProperty( + "jna.library.path", + "C:\\Users\\Hydros\\IdeaProjects\\RuneFactory\\src\\main\\rust\\src\\build" + ) + } + + fun getInstance(): HelloWorldWrapper { + val options = Native.getLibraryOptions(HelloWorldWrapper::class.java) + options[Library.OPTION_FUNCTION_MAPPER] = NativeFunctionMapper() + return Native.load("hello", HelloWorldWrapper::class.java, options) as HelloWorldWrapper + } + + } + + @NativeFunction(name ="_ZN5hello7get_int17h5cc51eaee082b02cE") + fun get_int(): NativeLong +} + diff --git a/src/main/kotlin/native/NativeFunction.kt b/src/main/kotlin/native/NativeFunction.kt new file mode 100644 index 0000000..5662262 --- /dev/null +++ b/src/main/kotlin/native/NativeFunction.kt @@ -0,0 +1,30 @@ +package native + +import com.sun.jna.NativeLibrary +import com.sun.jna.win32.StdCallFunctionMapper +import java.lang.reflect.Method + +/** + * Annotation used to specify the name of a native function. + * + * @param name The name of the native function. + */ +annotation class NativeFunction(val name: String) + +/** + * Mapper class that extends [StdCallFunctionMapper] to using the name from the [NativeFunction] annotation if present + * instead of the default name mapping. + * + * @see StdCallFunctionMapper + */ +class NativeFunctionMapper : StdCallFunctionMapper() { + + /** + * Overrides the default function name mapping to use the name from the [NativeFunction] annotation if present + * + * @see StdCallFunctionMapper.getFunctionName + */ + override fun getFunctionName(library: NativeLibrary?, method: Method): String { + return method.getAnnotation(NativeFunction::class.java)?.name ?: super.getFunctionName(library, method) + } +} \ No newline at end of file diff --git a/src/main/rust/cargo.toml b/src/main/rust/cargo.toml new file mode 100644 index 0000000..61e2a18 --- /dev/null +++ b/src/main/rust/cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "hello_world" +version = "0.1.0" +edition = "2021" + +[dependencies] + +[build] +rustflags = ["-C", "prefer-dynamic"] \ No newline at end of file diff --git a/src/main/rust/src/hello.rs b/src/main/rust/src/hello.rs new file mode 100644 index 0000000..22d6d15 --- /dev/null +++ b/src/main/rust/src/hello.rs @@ -0,0 +1,3 @@ +pub extern fn get_int() -> i32 { + return 42; +} \ No newline at end of file diff --git a/src/test/kotlin/native/DllLoadTest.kt b/src/test/kotlin/native/DllLoadTest.kt new file mode 100644 index 0000000..86f0c97 --- /dev/null +++ b/src/test/kotlin/native/DllLoadTest.kt @@ -0,0 +1,14 @@ +package native + +import kotlin.test.Test +import kotlin.test.assertEquals + +class DllLoadTest{ + + @Test + fun testLoadDll(){ + val hello = HelloWorldWrapper.getInstance() + val i = hello.get_int() + assertEquals(i.toInt(), 42) + } +} diff --git a/src/test/kotlin/native/hello.dll b/src/test/kotlin/native/hello.dll new file mode 100644 index 0000000..fc0fd9c Binary files /dev/null and b/src/test/kotlin/native/hello.dll differ