Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
FredYeye committed Dec 13, 2022
1 parent e1dcab2 commit f94d657
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 252 deletions.
418 changes: 225 additions & 193 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
glutin = "0.29.0"
glutin = "0.30.3"
glutin-winit = "0.2.1"
winit = "0.27.5"
raw-window-handle = "0.5.0"
egui = "0.20.1"
gl = "0.14.0"
egui = "0.18.1"
miniserde = "0.1.24"

[dependencies.windows]
version = "0.39.0"
version = "0.43.0"
features = [
"Data_Xml_Dom",
"Win32_Foundation",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Super Pang | 0.246
- [x] allow window resizing
- [ ] add some cool example screenshot
- [ ] support for gradius 1 arcade
- [ ] support for smash tv snes (enemy type/count)
- [ ] support for smash tv snes (enemy type/count)
gradius 3 (arcade) can extend the rank range (0-16 -> 0-31). maybe a loop 2 thing? consider supporting this.
101 changes: 81 additions & 20 deletions src/egui_glutin.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
use egui::{Modifiers, RawInput};
use glutin::{ContextWrapper, PossiblyCurrent};
use glutin::event_loop::ControlFlow;
use glutin::event::*;
use glutin::{context::PossiblyCurrentContext, surface::{Surface, WindowSurface, SurfaceAttributesBuilder, GlSurface}, prelude::{GlConfig, GlDisplay, NotCurrentGlContextSurfaceAccessor}, display::GetGlDisplay};
use raw_window_handle::HasRawWindowHandle;
use winit::{event::{VirtualKeyCode, Event, WindowEvent, ElementState}, event_loop::ControlFlow};
use std::{ffi::{CString, c_void}, ptr, str::from_utf8};

use crate::GuiState;

pub struct GlutinState {
pub window: winit::window::Window,
pub gl_ctx: PossiblyCurrentContext,
pub gl_display: glutin::display::Display,
pub gl_surface: Surface<WindowSurface>,
}

pub struct EguiState {
pub windowed_context: ContextWrapper<PossiblyCurrent, glutin::window::Window>,
pub glutin_state: GlutinState,

pub ctx: egui::Context,
pub pos_in_points: Option<egui::Pos2>,
Expand All @@ -23,15 +30,52 @@ pub struct EguiState {
window_size: (u32, u32),
}

pub fn setup_egui_glutin(el: &glutin::event_loop::EventLoop<()>, window_size: (u32, u32)) -> EguiState {
let wb = glutin::window::WindowBuilder::new()
.with_inner_size(glutin::dpi::LogicalSize::new(window_size.0, window_size.1))
.with_title("Game data reader 0.8");
pub fn setup_egui_glutin(el: &winit::event_loop::EventLoop<()>, window_size: (u32, u32)) -> EguiState {
let wb = winit::window::WindowBuilder::new()
.with_inner_size(winit::dpi::LogicalSize::new(window_size.0, window_size.1))
.with_title("Game data reader 0.9");

let (window, gl_config) = glutin_winit::DisplayBuilder::new()
.with_window_builder(Some(wb))
.build(&el, <_>::default(), |configs| {
configs
.filter(|c| c.srgb_capable())
.max_by_key(|c| c.num_samples())
.unwrap()
}).unwrap();

let window = window.unwrap();
let raw_window_handle = window.raw_window_handle();
let gl_display = gl_config.display();

let context_attributes = glutin::context::ContextAttributesBuilder::new()
.with_profile(glutin::context::GlProfile::Core)
.with_context_api(glutin::context::ContextApi::OpenGl(Some(
glutin::context::Version::new(4, 5),
)))
.build(Some(raw_window_handle));

let (gl_surface, gl_ctx) = {
let attrs = SurfaceAttributesBuilder::<glutin::surface::WindowSurface>::new().build(
raw_window_handle,
std::num::NonZeroU32::new(window_size.0).unwrap(),
std::num::NonZeroU32::new(window_size.1).unwrap(),
);

let surface = unsafe { match gl_display.create_window_surface(&gl_config, &attrs) {
Ok(o) => o,
Err(_) => todo!("omg"),
}};

let context = unsafe { match gl_display.create_context(&gl_config, &context_attributes) {
Ok(o) => o,
Err(_) => todo!("omg"),
}}.make_current(&surface).unwrap();
(surface, context)
};

let windowed_context = glutin::ContextBuilder::new().build_windowed(wb, &el).unwrap();
let windowed_context = unsafe{windowed_context.make_current().unwrap()};
gl::load_with(|symbol| (gl_display.get_proc_address(&CString::new(symbol).unwrap()) as _));

gl::load_with(|symbol| windowed_context.get_proc_address(symbol));
unsafe {
gl::Enable(gl::BLEND);
gl::Disable(gl::DEPTH_TEST);
Expand All @@ -45,7 +89,12 @@ pub fn setup_egui_glutin(el: &glutin::event_loop::EventLoop<()>, window_size: (u
let frag_e = include_str!("shader_e.frag");

EguiState {
windowed_context: windowed_context,
glutin_state: GlutinState {
window: window,
gl_ctx: gl_ctx,
gl_display: gl_display,
gl_surface: gl_surface,
},

ctx: egui::Context::default(),
pos_in_points: None,
Expand Down Expand Up @@ -274,7 +323,7 @@ fn compile_shader(source: &str, shader_type: u32) -> u32 {
}
}

pub fn update_textures(tex_set: egui::epaint::ahash::AHashMap<egui::TextureId, egui::epaint::ImageDelta>, tex_e: u32) {
pub fn update_textures(tex_set: Vec<(egui::TextureId, egui::epaint::ImageDelta)>, tex_e: u32) {
for (id, image_delta) in &tex_set {
let pixels: Vec<(u8, u8, u8, u8)> = match &image_delta.image {
egui::ImageData::Color(image) => {
Expand All @@ -283,7 +332,7 @@ pub fn update_textures(tex_set: egui::epaint::ahash::AHashMap<egui::TextureId, e

egui::ImageData::Font(image) => {
let gamma = 1.0;
image.srgba_pixels(gamma).map(|color| color.to_tuple()).collect()
image.srgba_pixels(Some(gamma)).map(|color| color.to_tuple()).collect()
}
};

Expand Down Expand Up @@ -448,9 +497,9 @@ pub fn event_handling(event: Event<()>, control_flow: &mut ControlFlow, egui_sta
WindowEvent::MouseInput{state, button, ..} => {
if let Some(pos_in_points_temp) = egui_state.pos_in_points {
if let Some(button) = match button {
glutin::event::MouseButton::Left => Some(egui::PointerButton::Primary),
glutin::event::MouseButton::Right => Some(egui::PointerButton::Secondary),
glutin::event::MouseButton::Middle => Some(egui::PointerButton::Middle),
winit::event::MouseButton::Left => Some(egui::PointerButton::Primary),
winit::event::MouseButton::Right => Some(egui::PointerButton::Secondary),
winit::event::MouseButton::Middle => Some(egui::PointerButton::Middle),
_ => None,
}
{
Expand All @@ -459,8 +508,8 @@ pub fn event_handling(event: Event<()>, control_flow: &mut ControlFlow, egui_sta
pos: pos_in_points_temp,
button,
pressed: match state {
glutin::event::ElementState::Pressed => true,
glutin::event::ElementState::Released => false,
winit::event::ElementState::Pressed => true,
winit::event::ElementState::Released => false,
},
modifiers: Modifiers::default(),
}
Expand All @@ -469,8 +518,20 @@ pub fn event_handling(event: Event<()>, control_flow: &mut ControlFlow, egui_sta
}
}

WindowEvent::MouseWheel {delta, ..} => {
if let winit::event::MouseScrollDelta::LineDelta(_, y) = delta {
egui_state.raw_input.events.push(
egui::Event::Scroll(egui::vec2(0.0, y * 35.0))
);
}
}

WindowEvent::Resized(physical_size) => {
egui_state.windowed_context.resize(physical_size);
egui_state.glutin_state.gl_surface.resize(
&egui_state.glutin_state.gl_ctx,
std::num::NonZeroU32::new(physical_size.width).unwrap(),
std::num::NonZeroU32::new(physical_size.width).unwrap(),
);
egui_state.window_size = (physical_size.width, physical_size.height);

unsafe {
Expand Down
8 changes: 6 additions & 2 deletions src/game_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ impl Games {
Rank {
data_points: std::collections::VecDeque::new(),
offset: 0x041D,
steps: 16,
steps: 17,
//todo: what's the valid range? starting rank on normal difficulty is 2, demo 0.
// max rank appears to be 16. 0-16? unusual
}
),
},
Expand All @@ -195,7 +197,9 @@ impl Games {
Rank {
data_points: std::collections::VecDeque::new(),
offset: 0x39C0,
steps: 16,
steps: 17,
//todo: valid range? 0-16?
// if 39C3 != 0, then the range is 0-31!
}
),
},
Expand Down
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#![windows_subsystem = "windows"]

use egui::{Context, plot::{Plot, Line, Values as EguiValues, LineStyle}, Color32, RichText};
use glutin::event_loop::{ControlFlow, EventLoop};
use egui::{Context, plot::{Plot, Line, LineStyle, PlotPoints}, Color32, RichText};
use glutin::surface::GlSurface;
use update::CurrentGame;
use winit::event_loop::{EventLoop, ControlFlow};

mod egui_glutin;
mod game_data;
Expand Down Expand Up @@ -89,6 +90,8 @@ fn main() {
},
};

egui_state.ctx.set_pixels_per_point(2.0);

let mut current_game = None;

el.run(move |event, _, control_flow| {
Expand Down Expand Up @@ -130,6 +133,7 @@ fn main() {
}
}


egui_state.ctx.begin_frame(egui_state.raw_input.take());

create_ui(&mut egui_state.ctx, &mut gui_state, &mut current_game); // add panels, windows and widgets to `egui_ctx` here
Expand All @@ -144,7 +148,7 @@ fn main() {
todo!();
}

egui_state.windowed_context.swap_buffers().unwrap();
egui_state.glutin_state.gl_surface.swap_buffers(&egui_state.glutin_state.gl_ctx).unwrap();
}
});
}
Expand Down Expand Up @@ -212,7 +216,7 @@ fn rank_graph(ctx: &mut Context, gui_state: &mut GuiState, rank: &mut update::Ra
}

plot_ui.line(
Line::new(EguiValues::from_ys_f32(rank.data_points.as_slices().0))
Line::new(PlotPoints::from_ys_f32(rank.data_points.as_slices().0))
.color(Color32::from_rgb(rgb[0], rgb[1], rgb[2]))
.style(LineStyle::Solid)
)
Expand Down
17 changes: 14 additions & 3 deletions src/shader_e.frag
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ out vec4 color_out;

//-----

void main()
{
color_out = color * texture(tex_sampler, uv);
vec3 srgb_gamma_from_linear(vec3 rgb) { // 0-1 sRGB gamma from 0-1 linear
bvec3 cutoff = lessThan(rgb, vec3(0.0031308));
vec3 lower = rgb * vec3(12.92);
vec3 higher = vec3(1.055) * pow(rgb, vec3(1.0 / 2.4)) - vec3(0.055);
return mix(higher, lower, vec3(cutoff));
}

vec4 srgba_gamma_from_linear(vec4 rgba) { // 0-1 sRGBA gamma from 0-1 linear
return vec4(srgb_gamma_from_linear(rgba.rgb), rgba.a);
}

void main() {
vec4 texture_in_gamma = srgba_gamma_from_linear(texture2D(tex_sampler, uv));
color_out = color * texture_in_gamma;
}
18 changes: 2 additions & 16 deletions src/shader_e.vert
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,7 @@ out vec4 color;

//-----

vec3 linear_from_srgb(vec3 srgb) // 0-1 linear from 0-255 sRGB
{
bvec3 cutoff = lessThan(srgb, vec3(10.31475));
vec3 lower = srgb / vec3(3294.6);
vec3 higher = pow((srgb + vec3(14.025)) / vec3(269.025), vec3(2.4));
return mix(higher, lower, cutoff);
}

vec4 linear_from_srgba(vec4 srgba)
{
return vec4(linear_from_srgb(srgba.rgb), srgba.a / 255.0);
}

void main()
{
void main() {
gl_Position = vec4(
2.0 * vertices.x / size.x - 1.0,
1.0 - 2.0 * vertices.y / size.y,
Expand All @@ -36,5 +22,5 @@ void main()
);

uv = uv_in;
color = linear_from_srgba(color_in);
color = color_in / 255.0;
}
15 changes: 5 additions & 10 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ fn get_game_name(handle: HANDLE, info: &MODULEINFO, emu: &game_data::Emulator) -

unsafe {
let p_raw_str = raw_str.as_mut_ptr() as *mut _ as *mut c_void;
let mut count = 0;
ReadProcessMemory(handle, game_name_offset, p_raw_str, raw_str.len() - 1, &mut count);
ReadProcessMemory(handle, game_name_offset, p_raw_str, raw_str.len() - 1, None);
}

let terminator = raw_str.into_iter().position(|x| x == 0).unwrap();
Expand All @@ -164,8 +163,7 @@ fn get_mame_offset(handle: HANDLE, dll_base: u64, offset_list: Vec<u64>) -> u64
for offset in offset_list {
let base = (address + offset) as *const c_void;
let p_address = &mut address as *mut _ as *mut c_void;
let mut count = 0;
ReadProcessMemory(handle, base, p_address, 8, &mut count);
ReadProcessMemory(handle, base, p_address, 8, None);
}

address
Expand Down Expand Up @@ -194,8 +192,7 @@ fn update_rank(rank: &mut Rank, game: &game_data::Games, handle: HANDLE, base_of
unsafe {
let base = (base_offset + rank.offset as u64) as *const c_void;
let p_rank = &mut temp_rank as *mut _ as *mut c_void;
let mut count = 0;
ReadProcessMemory(handle, base, p_rank, 1, &mut count);
ReadProcessMemory(handle, base, p_rank, 1, None);
}

temp_rank = game.format_rank(temp_rank);
Expand All @@ -217,17 +214,15 @@ fn update_smash_tv(smash_tv: &mut SmashTV, handle: HANDLE, base_offset: u64) {
unsafe {
let base = (base_offset + 0x1902) as *const c_void;
let p_rank = temp.as_mut_ptr() as *mut _ as *mut c_void;
let mut count = 0;
ReadProcessMemory(handle, base, p_rank, LIST_COUNT, &mut count);
ReadProcessMemory(handle, base, p_rank, LIST_COUNT, None);
}

let mut temp2 = 0;

unsafe {
let base = (base_offset + 0x18E4) as *const c_void;
let p_rank = &mut temp2 as *mut _ as *mut c_void;
let mut count = 0;
ReadProcessMemory(handle, base, p_rank, 1, &mut count);
ReadProcessMemory(handle, base, p_rank, 1, None);
}

smash_tv.active_enemies[0] = temp2;
Expand Down

0 comments on commit f94d657

Please sign in to comment.