begun, the native interfacing has

This commit is contained in:
dtookey 2023-08-16 09:00:58 -04:00
parent ee9287972f
commit b65b0c368d
10 changed files with 90 additions and 55 deletions

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -15,6 +15,7 @@ dependencies {
testImplementation("org.mockito.kotlin:mockito-kotlin:5.0.0") testImplementation("org.mockito.kotlin:mockito-kotlin:5.0.0")
implementation("net.java.dev.jna:jna:latest.release") implementation("net.java.dev.jna:jna:latest.release")
implementation(kotlin("reflect"))
} }
tasks.test { tasks.test {

View File

@ -73,13 +73,6 @@ class RSAgent(override val automaton: Automaton = RobotAutomaton()) : RSOrchestr
* - Clicks the default "Accept" hotkey to start crafting. * - Clicks the default "Accept" hotkey to start crafting.
* - Waits for the specified crafting duration plus random variance. * - 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. * @param taskParams The [StandingTaskParams] configuring the task details like bank location, hotkeys, and durations.
*/ */
override fun processAtBank( override fun processAtBank(
@ -118,12 +111,6 @@ class RSAgent(override val automaton: Automaton = RobotAutomaton()) : RSOrchestr
* *
* - Waits for the randomized crafting duration. * - Waits for the randomized crafting duration.
* *
* Usage example:
* ```
* val params = TravelTaskParams(...)
* orchestrator.processAtStationNearBank(params)
* ```
*
* @param taskParams The [TravelTaskParams] configuring the task details. * @param taskParams The [TravelTaskParams] configuring the task details.
*/ */
override fun processAtStationNearBank( 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. * 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. * @return The Point position of the mouse after user positions it.
*/ */
override fun getBankPoint(): Point { override fun getBankPoint(): Point {
@ -184,19 +160,10 @@ class RSAgent(override val automaton: Automaton = RobotAutomaton()) : RSOrchestr
/** /**
* Sleeps for a specified number of game ticks. * Sleeps for a specified number of game ticks.
* *
* This method calculates the total sleep duration based on the number of ticks * A brief random variance is also added to the sleep duration to add some less-robotic behavior.
* 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)
* ```
* *
* @param n The number of game ticks to sleep for. * @param n The number of game ticks to sleep for.
* @see TICK_DURATION_MS
*/ */
override fun sleepForNTicks(n: Long) { override fun sleepForNTicks(n: Long) {
val latencyPadding = LATENCY_PADDING_MS val latencyPadding = LATENCY_PADDING_MS

View File

@ -245,27 +245,9 @@ object RunescapeRoutines {
* *
* @param volume The number of inventory slots to process at the furnace. * @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. * furnaceFromChest The Point location of the furnace from the bank chest.
* chestFromFurnace The Point location of the bank chest from the furnace. * 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) { fun processInventoryAtFurnace(volume: Int) {
//these two points are specific to my computer. we need to export these into a file or something //these two points are specific to my computer. we need to export these into a file or something

View File

@ -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
}

View File

@ -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)
}
}

9
src/main/rust/cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"
[dependencies]
[build]
rustflags = ["-C", "prefer-dynamic"]

View File

@ -0,0 +1,3 @@
pub extern fn get_int() -> i32 {
return 42;
}

View File

@ -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)
}
}

Binary file not shown.