No console window in windows executable
This commit is contained in:
+15
-24
@@ -2,12 +2,12 @@ image: Visual Studio 2017
|
||||
environment:
|
||||
RUST_TEST_THREADS: 1
|
||||
matrix:
|
||||
- TARGET: x86_64-pc-windows-msvc
|
||||
RUST_CHANNEL: beta
|
||||
WPD_LIB_PATH: "C:/dl/wpdpack/WpdPack/Lib/x64/Packet.lib"
|
||||
PYTHON: "C:\\Python36-x64"
|
||||
PYTHON_ARCH: "64"
|
||||
VCVARS: "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\vcvars64.bat"
|
||||
- TARGET: x86_64-pc-windows-msvc
|
||||
RUST_CHANNEL: beta
|
||||
WPD_LIB_PATH: "C:/dl/wpdpack/WpdPack/Lib/x64/Packet.lib"
|
||||
PYTHON: "C:\\Python36-x64"
|
||||
PYTHON_ARCH: "64"
|
||||
VCVARS: "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\vcvars64.bat"
|
||||
install:
|
||||
- SET PATH=%PYTHON%;%path%
|
||||
- ps: mkdir C:/dl
|
||||
@@ -22,29 +22,20 @@ install:
|
||||
- choco install winpcap
|
||||
- rustc -V
|
||||
- cargo -V
|
||||
test: false
|
||||
build: true
|
||||
build_script:
|
||||
- cargo build --release --verbose
|
||||
- cargo build --release --verbose
|
||||
after_build:
|
||||
- ps: cd ${env:APPVEYOR_BUILD_FOLDER}/gui
|
||||
- python -m venv env
|
||||
- ps: .\env\Scripts\activate.ps1
|
||||
- pip install -r requirements.txt
|
||||
- ps: cp ${env:APPVEYOR_BUILD_FOLDER}\target\release\meter.dll libmeter.pyd
|
||||
- pyinstaller -F -i ..\assets\albion-stats-icon.ico -r libmeter.pyd meter.py
|
||||
- ps: deactivate
|
||||
- ps: mv dist\meter.exe ..\albion-online-stats.exe
|
||||
- ps: ls
|
||||
- ps: ls ..\
|
||||
artifacts:
|
||||
path: albion-online-stats.exe
|
||||
name: binary
|
||||
- ps: cd ${env:APPVEYOR_BUILD_FOLDER}/gui
|
||||
- pip install -r requirements.txt
|
||||
- ps: cp ${env:APPVEYOR_BUILD_FOLDER}/target/release/meter.dll libmeter.pyd
|
||||
- pyinstaller -F -w -i ../assets/albion-stats-icon.ico meter.py
|
||||
deploy:
|
||||
provider: GitHub
|
||||
auth_token:
|
||||
secure: cB8zvJaO/tS/Z3v4038LBCsRaO9LqrtRS0CV/eLfHnG5SefWKNSObALSvphoQxC4
|
||||
artifact: binary
|
||||
secure: ${env:GITHUB_TOKEN}
|
||||
artifact: ${env:APPVEYOR_BUILD_FOLDER}/gui/dist/albion-stats.exe
|
||||
draft: false
|
||||
prerelease: false
|
||||
on:
|
||||
APPVEYOR_REPO_TAG: true # deploy on tag push only
|
||||
APPVEYOR_REPO_TAG: true # deploy on tag push only
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#[macro_use] extern crate cpython;
|
||||
#[macro_use] extern crate lazy_static;
|
||||
extern crate bytes;
|
||||
extern crate packet_sniffer;
|
||||
extern crate protocol16;
|
||||
|
||||
use std::fs::File;
|
||||
use std::sync::mpsc::{Sender, Receiver, channel};
|
||||
use std::thread;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use simplelog::*;
|
||||
use log::*;
|
||||
use cpython::{Python, PyResult, PyDict, PyList, PyString, PythonObject, PyObject, PyFloat};
|
||||
|
||||
use packet_sniffer::UdpPacket;
|
||||
|
||||
mod game_protocol;
|
||||
mod meter;
|
||||
|
||||
lazy_static! {
|
||||
static ref METER: Mutex<meter::Meter> = Mutex::new(meter::Meter::new());
|
||||
}
|
||||
|
||||
fn get_instance_session(py: Python) -> PyResult<PyList> {
|
||||
let meter = &mut METER.lock().unwrap();
|
||||
|
||||
if let Some(session) = meter.get_instance_session() {
|
||||
let stats = session.iter().map(|s| {
|
||||
let dict = PyDict::new(py);
|
||||
|
||||
dict.set_item(py, "player", PyString::new(py, &s.player)).unwrap();
|
||||
dict.set_item(py, "damage", PyFloat::new(py, s.damage.into())).unwrap();
|
||||
dict.set_item(py, "time_in_combat", PyFloat::new(py, s.time_in_combat.into())).unwrap();
|
||||
dict.set_item(py, "dps", PyFloat::new(py, s.dps.value().into())).unwrap();
|
||||
|
||||
dict.into_object()
|
||||
}).collect::<Vec<PyObject>>();
|
||||
|
||||
return Ok(PyList::new(py, stats.as_slice()));
|
||||
}
|
||||
|
||||
return Ok(PyList::new(py, Vec::<PyObject>::new().as_slice()));
|
||||
}
|
||||
|
||||
fn initialize(_py: Python) -> PyResult<u32> {
|
||||
CombinedLogger::init(vec![
|
||||
WriteLogger::new(
|
||||
LevelFilter::Trace,
|
||||
Config::default(),
|
||||
File::create("damage-meter.log").unwrap(),
|
||||
),
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
thread::spawn(move || {
|
||||
let (tx, rx): (Sender<UdpPacket>, Receiver<UdpPacket>) = channel();
|
||||
|
||||
packet_sniffer::receive(tx);
|
||||
|
||||
loop {
|
||||
if let Ok(packet) = rx.recv() {
|
||||
let meter = &mut METER.lock().unwrap();
|
||||
if packet.destination_port != 5056 && packet.source_port != 5056 {
|
||||
continue;
|
||||
}
|
||||
let messages = game_protocol::decode(&packet.payload);
|
||||
|
||||
for msg in messages {
|
||||
debug!("Found message {:?}", msg);
|
||||
|
||||
match msg {
|
||||
game_protocol::Message::Leave(msg) => meter.register_leave(msg.source).unwrap_or(()),
|
||||
game_protocol::Message::NewCharacter(msg) => meter.register_player(&msg.character_name, msg.source),
|
||||
game_protocol::Message::CharacterStats(msg) => meter.register_main_player(&msg.character_name, msg.source),
|
||||
game_protocol::Message::HealthUpdate(msg) => meter.register_damage_dealt(msg.target, msg.value).unwrap_or(()),
|
||||
game_protocol::Message::RegenerationHealthChanged(msg) => {
|
||||
match msg.regeneration_rate {
|
||||
Some(_) => meter.register_combat_leave(msg.source).unwrap_or(()),
|
||||
None => meter.register_combat_enter(msg.source).unwrap_or(()) // TODO: handle death
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
py_module_initializer!(libmeter, initliblibmeter, PyInit_libmeter, |py, m | {
|
||||
m.add(py, "__doc__", "This module is implemented in Rust")?;
|
||||
m.add(py, "initialize", py_fn!(py, initialize()))?;
|
||||
m.add(py, "get_instance_session", py_fn!(py, get_instance_session()))?;
|
||||
Ok(())
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
import libmeter
|
||||
|
||||
import sys
|
||||
import random
|
||||
from PySide2.QtWidgets import (QApplication, QLabel, QPushButton,
|
||||
QVBoxLayout, QWidget, QTableWidget, QHeaderView, QHBoxLayout,
|
||||
QTableWidgetItem)
|
||||
from PySide2.QtCore import Slot, Qt
|
||||
|
||||
from PySide2.QtCore import QTimer
|
||||
|
||||
import libmeter
|
||||
|
||||
|
||||
class Stat:
|
||||
def __init__(self, name, damage, time_in_combat, dps):
|
||||
self.name = name
|
||||
self.damage = str(damage)
|
||||
self.time_in_combat = str(time_in_combat)
|
||||
self.dps = str(dps)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.name == other.name and self.damage == other.damage and self.time_in_combat == other.time_in_combat and self.dps == other.dps
|
||||
|
||||
|
||||
def get_instance_session():
|
||||
session = libmeter.get_instance_session()
|
||||
# session = [
|
||||
# {'player': 'A', 'damage': 1234.02, 'time_in_combat': 12.0, 'dps': 12.4234},
|
||||
# {'player': 'B', 'damage': 5435.02, 'time_in_combat': 12.0, 'dps': 12},
|
||||
# {'player': 'C', 'damage': 23.02, 'time_in_combat': 12.0, 'dps': 13},
|
||||
# {'player': 'D', 'damage': 23.02, 'time_in_combat': 12.0, 'dps': 0}
|
||||
# ]
|
||||
|
||||
return [Stat(s['player'], s['damage'], s['time_in_combat'], s['dps']) for s in session]
|
||||
|
||||
|
||||
class MyWidget(QWidget):
|
||||
def __init__(self):
|
||||
QWidget.__init__(self)
|
||||
|
||||
self.session = None
|
||||
|
||||
self.table = QTableWidget()
|
||||
self.table.setColumnCount(3)
|
||||
self.table.setHorizontalHeaderLabels(["Player", "Damage", "DPS"])
|
||||
self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
|
||||
self.layout = QHBoxLayout()
|
||||
self.layout.addWidget(self.table)
|
||||
self.setLayout(self.layout)
|
||||
|
||||
self.fill_table()
|
||||
|
||||
timer = QTimer(self)
|
||||
timer.timeout.connect(self.fill_table)
|
||||
timer.start(5000)
|
||||
|
||||
def session_changed(self, session):
|
||||
return self.session != session
|
||||
|
||||
def fill_table(self, data=None):
|
||||
new_session = get_instance_session()
|
||||
|
||||
if not self.session_changed(new_session):
|
||||
return
|
||||
|
||||
self.session = new_session
|
||||
|
||||
session = sorted(new_session, key=lambda s: float(s.damage), reverse=True)
|
||||
|
||||
for idx, stats in enumerate(session):
|
||||
self.table.removeRow(idx)
|
||||
self.table.insertRow(idx)
|
||||
self.table.setItem(idx, 0, QTableWidgetItem(stats.name))
|
||||
self.table.setItem(idx, 1, QTableWidgetItem(stats.damage))
|
||||
self.table.setItem(idx, 2, QTableWidgetItem(stats.dps))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
libmeter.initialize()
|
||||
|
||||
WIDTH = 512
|
||||
HEIGHT = 180
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
geometry = app.screens()[0].size()
|
||||
|
||||
widget = MyWidget()
|
||||
widget.setWindowOpacity(0.5)
|
||||
widget.resize(WIDTH, HEIGHT)
|
||||
widget.move(0, geometry.height() - HEIGHT - 280)
|
||||
|
||||
widget.setWindowTitle('Damage Meter')
|
||||
|
||||
widget.setWindowFlag(Qt.WindowStaysOnTopHint)
|
||||
widget.show()
|
||||
|
||||
sys.exit(app.exec_())
|
||||
Reference in New Issue
Block a user