Skip to content

Commit ecf417e

Browse files
committed
Export town_hall_details in release CI builds
1 parent a94b4d5 commit ecf417e

File tree

4 files changed

+84
-3
lines changed

4 files changed

+84
-3
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
mv target/i686-pc-windows-msvc/release/scrollmap_render_all_ships.dll ./mods/
2525
mv target/i686-pc-windows-msvc/release/shipyard_details.dll ./mods/
2626
mv target/i686-pc-windows-msvc/release/tavern_show_all_sailors.dll ./mods/
27+
mv target/i686-pc-windows-msvc/release/town_hall_details.dll ./mods/
2728
mkdir files
2829
mv target/i686-pc-windows-msvc/release/aimcli.exe ./files
2930
mv target/i686-pc-windows-msvc/release/cprcli.exe ./files

p3-api/src/class35.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use std::{ffi::c_void, mem, ptr};
2+
3+
use log::debug;
4+
5+
use crate::{data::p3_ptr::P3Pointer, Point};
6+
7+
const CLASS35_PTR_ADDRESS: *const u32 = 0x006CBDC8 as _;
8+
9+
#[derive(Clone, Debug)]
10+
pub struct Class35Ptr {
11+
pub address: u32,
12+
}
13+
14+
#[derive(Clone, Debug)]
15+
#[repr(C)]
16+
pub struct ShipRoute {
17+
pub points: *const c_void,
18+
pub len: i32,
19+
}
20+
21+
#[derive(Clone, Debug)]
22+
#[repr(C)]
23+
pub struct ShipRouteArgs {
24+
pub args_inner: *const ShipRouteArgsInner,
25+
pub route_type: i32,
26+
}
27+
28+
#[derive(Clone, Debug)]
29+
#[repr(C)]
30+
pub struct ShipRouteArgsInner {
31+
pub source: Point<i16>,
32+
pub destination: Point<i16>,
33+
}
34+
35+
impl Class35Ptr {
36+
pub unsafe fn new() -> Self {
37+
Self { address: *CLASS35_PTR_ADDRESS }
38+
}
39+
40+
pub unsafe fn calculate_ship_route(&self, source: Point<i16>, destination: Point<i16>) -> *const ShipRoute {
41+
let args_inner = ShipRouteArgsInner { source, destination };
42+
let args = ShipRouteArgs {
43+
args_inner: &args_inner,
44+
route_type: 2,
45+
};
46+
let mut ship_route: *const ShipRoute = ptr::null_mut();
47+
debug!("Calling calculate_ship_route orig");
48+
let orig: extern "thiscall" fn(this: u32, route_args: *const ShipRouteArgs, route: *mut *const ShipRoute) -> i32 = mem::transmute(0x00445010);
49+
orig(self.address, &args, &mut ship_route);
50+
debug!("Calling calculate_ship_route survived! {ship_route:?}");
51+
ship_route
52+
}
53+
}
54+
55+
impl P3Pointer for Class35Ptr {
56+
fn get_address(&self) -> u32 {
57+
self.address
58+
}
59+
}

p3-api/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(clippy::missing_safety_doc)]
22
extern crate num_derive;
33

4+
pub mod class35;
45
pub mod data;
56
pub mod facility;
67
pub mod game_world;
@@ -14,6 +15,19 @@ pub mod ships;
1415
pub mod town;
1516
pub mod ui;
1617

18+
#[derive(Clone, Debug)]
19+
#[repr(C)]
20+
pub struct Point<T> {
21+
pub x: T,
22+
pub y: T,
23+
}
24+
25+
impl<T> Point<T> {
26+
pub const fn new(x: T, y: T) -> Self {
27+
Self { x, y }
28+
}
29+
}
30+
1731
// https://stackoverflow.com/a/28175593/1569755
1832
fn latin1_to_string(s: &[u8]) -> String {
1933
s.iter().take_while(|c| **c != 0).map(|&c| c as char).collect()

p3-api/src/town/static_town_data.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::data::p3_ptr::P3Pointer;
1+
use crate::{
2+
data::{enums::TownId, p3_ptr::P3Pointer},
3+
Point,
4+
};
25

36
pub const TOWN_DATA_ADDRESS: u32 = 0x006DDB90;
47
pub const TOWN_DATA_SIZE: u32 = 0x34;
@@ -9,9 +12,9 @@ pub struct StaticTownDataPtr {
912
}
1013

1114
impl StaticTownDataPtr {
12-
pub fn new(town_id: u32) -> Self {
15+
pub fn new(town_id: TownId) -> Self {
1316
Self {
14-
address: TOWN_DATA_ADDRESS + town_id * TOWN_DATA_SIZE,
17+
address: TOWN_DATA_ADDRESS + town_id as u32 * TOWN_DATA_SIZE,
1518
}
1619
}
1720

@@ -22,6 +25,10 @@ impl StaticTownDataPtr {
2225
pub unsafe fn get_anfahrt_y_pos(&self) -> i32 {
2326
self.get(0x24)
2427
}
28+
29+
pub unsafe fn get_point_i16(&self) -> Point<i16> {
30+
Point::new(self.get_anfahrt_x_pos() as _, self.get_anfahrt_y_pos() as _)
31+
}
2532
}
2633

2734
impl P3Pointer for StaticTownDataPtr {

0 commit comments

Comments
 (0)