Skip to content

Commit

Permalink
Use plain bool for gameplay_affecting
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank authored and jieyouxu committed Feb 24, 2024
1 parent f651096 commit 87f714c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 53 deletions.
7 changes: 1 addition & 6 deletions hook/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{

use anyhow::{Context, Result};
use hook_resolvers::GasFixResolution;
use mint_lib::mod_info::GameplayAffecting;
use mint_lib::DRGInstallationType;
use windows::Win32::System::Memory::{VirtualProtect, PAGE_EXECUTE_READWRITE};

Expand Down Expand Up @@ -64,11 +63,7 @@ pub unsafe fn initialize() -> Result<()> {
HookUFunctionBind.enable()?;

if let Ok(server_name) = &globals().resolution.server_name
&& globals()
.meta
.mods
.iter()
.any(|m| m.gameplay_affecting == GameplayAffecting::Yes)
&& globals().meta.mods.iter().any(|m| m.gameplay_affecting)
{
GetServerName
.initialize(
Expand Down
10 changes: 1 addition & 9 deletions mint_lib/src/mod_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ impl From<&str> for ModIdentifier {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum GameplayAffecting {
/// Sandbox, approved and unknown mods
Yes,
/// Verified mods
No,
}

/// Stripped down mod info stored in the mod pak to be used in game
#[derive(Debug, Serialize, Deserialize)]
pub struct Meta {
Expand Down Expand Up @@ -162,7 +154,7 @@ pub struct MetaMod {
pub author: String,
pub approval: ApprovalStatus,
pub required: bool,
pub gameplay_affecting: GameplayAffecting,
pub gameplay_affecting: bool,
}

impl Meta {
Expand Down
6 changes: 3 additions & 3 deletions src/gui/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tracing::{debug, error, info};

use crate::integrate::{IntegrationErr, IntegrationErrKind};
use crate::mod_lints::{LintId, LintReport};
use crate::state::{GameplayAffecting, ModData_v0_1_0 as ModData, ModOrGroup};
use crate::state::{ModData_v0_1_0 as ModData, ModOrGroup};
use crate::{
error::IntegrationError,
providers::{FetchProgress, ModInfo, ModResolution, ModSpecification, ModStore},
Expand Down Expand Up @@ -180,7 +180,7 @@ impl ResolveMods {
#[derive(Debug)]
pub struct Integrate {
rid: RequestID,
result: Result<HashMap<ModInfo, GameplayAffecting>, IntegrationErr>,
result: Result<HashMap<ModInfo, bool>, IntegrationErr>,
}

impl Integrate {
Expand Down Expand Up @@ -401,7 +401,7 @@ async fn integrate_async(
config: MetaConfig,
rid: RequestID,
message_tx: Sender<Message>,
) -> Result<HashMap<ModInfo, GameplayAffecting>, IntegrationErr> {
) -> Result<HashMap<ModInfo, bool>, IntegrationErr> {
let update = false;

let mods = store
Expand Down
9 changes: 4 additions & 5 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,14 @@ impl App {
.get_gameplay_affecting_status(&info.resolution.url)
{
match status {
GameplayAffecting::No => mk_searchable_tag(
false => mk_searchable_tag(
ctx,
"Verified",
ui,
Some(egui::Color32::LIGHT_GREEN),
Some("Does not contain any gameplay affecting features or changes"),
),
GameplayAffecting::Yes => mk_searchable_tag(
true => mk_searchable_tag(
ctx,
"Not Verified",
ui,
Expand Down Expand Up @@ -1829,12 +1829,11 @@ impl eframe::App for App {
debug!(?mod_id);
// FIXME: cached version has `/mod-file-id` appended, but not the mod_id fed
// here from the GUI.
profile_is_verified &= self
profile_is_verified &= !self
.state
.store
.get_gameplay_affecting_status(&mod_id)
.unwrap_or(GameplayAffecting::Yes)
== GameplayAffecting::No;
.unwrap_or(true)
}

if profile_is_verified {
Expand Down
37 changes: 16 additions & 21 deletions src/integrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use uasset_utils::splice::{
use unreal_asset::reader::ArchiveTrait;

use crate::providers::ModInfo;
use crate::state::GameplayAffecting;
use crate::{get_pak_from_data, open_file};

use unreal_asset::{
Expand Down Expand Up @@ -165,7 +164,7 @@ pub fn integrate<P: AsRef<Path>>(
path_pak: P,
config: MetaConfig,
mods: Vec<(ModInfo, PathBuf)>,
) -> Result<HashMap<ModInfo, GameplayAffecting>, IntegrationErr> {
) -> Result<HashMap<ModInfo, bool>, IntegrationErr> {
let installation = DRGInstallation::from_pak_path(&path_pak).map_err(|e| IntegrationErr {
mod_ctxt: None,
kind: IntegrationErrKind::Generic(e),
Expand Down Expand Up @@ -404,11 +403,7 @@ pub fn integrate<P: AsRef<Path>>(
approval_status, ..
}) = mod_info.modio_tags
{
if approval_status == ApprovalStatus::Verified {
GameplayAffecting::No
} else {
GameplayAffecting::Yes
}
approval_status != ApprovalStatus::Verified
} else {
check_gameplay_affecting(
&fsd_lowercase_path_map,
Expand Down Expand Up @@ -629,12 +624,12 @@ pub fn integrate<P: AsRef<Path>>(
.map(|t| t.approval_status)
.unwrap_or(ApprovalStatus::Sandbox),
gameplay_affecting: match info.modio_tags.as_ref().map(|t| t.approval_status) {
Some(ApprovalStatus::Verified) => GameplayAffecting::No,
Some(_) => GameplayAffecting::Yes,
None => *gameplay_affecting_results
Some(ApprovalStatus::Verified) => false,
Some(_) => true,
None => gameplay_affecting_results
.iter()
.find_map(|(mod_info, res)| (*mod_info == *info).then_some(res))
.unwrap_or(&GameplayAffecting::Yes),
.find_map(|(mod_info, res)| (mod_info == info).then_some(*res))
.unwrap_or(true),
},
})
.collect(),
Expand Down Expand Up @@ -667,7 +662,7 @@ pub fn check_gameplay_affecting<F, M>(
fsd_pak_reader: &repak::PakReader,
mod_pak: &mut M,
mod_pak_reader: &repak::PakReader,
) -> Result<GameplayAffecting>
) -> Result<bool>
where
F: Read + Seek,
M: Read + Seek,
Expand All @@ -693,7 +688,7 @@ where
.into_iter()
.collect::<HashSet<_>>();

let check_asset = |data: Vec<u8>| -> Result<GameplayAffecting> {
let check_asset = |data: Vec<u8>| -> Result<bool> {
debug!("check_asset");
let asset = unreal_asset::AssetBuilder::new(
Cursor::new(data),
Expand All @@ -713,11 +708,11 @@ where
.unwrap_or(false)
{
// invalid import or import name is not whitelisted, unknown
return Ok(GameplayAffecting::Yes);
return Ok(true);
};
}

Ok(GameplayAffecting::No)
Ok(false)
};

let mod_lowercase_path_map = mod_pak_reader
Expand Down Expand Up @@ -751,22 +746,22 @@ where
fsd_pak_reader.get(path, fsd_pak)?
} else {
// not found, unknown
return Ok(GameplayAffecting::Yes);
return Ok(true);
};

let asset_result = check_asset(asset.clone())?;
debug!(?asset_result);

if asset_result == GameplayAffecting::Yes {
debug!("GameplayAffecting::Yes");
if asset_result {
debug!("GameplayAffecting: true");
debug!("{:#?}", asset.clone());
return Ok(GameplayAffecting::Yes);
return Ok(true);
}
}
}
}

Ok(GameplayAffecting::No)
Ok(false)
}

type ImportChain<'a> = Vec<Import<'a>>;
Expand Down
9 changes: 4 additions & 5 deletions src/mod_lints/auto_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::path::Path;
use anyhow::{bail, Context, Result};
use tracing::debug;

use mint_lib::mod_info::GameplayAffecting;
use unreal_asset::exports::ExportBaseTrait;
use unreal_asset::reader::ArchiveTrait;

Expand Down Expand Up @@ -99,7 +98,7 @@ where
.into_iter()
.collect::<HashSet<_>>();

let check_asset = |data: Vec<u8>| -> Result<GameplayAffecting> {
let check_asset = |data: Vec<u8>| -> Result<bool> {
debug!("check_asset");
let asset = unreal_asset::AssetBuilder::new(
Cursor::new(data),
Expand All @@ -119,11 +118,11 @@ where
.unwrap_or(false)
{
// invalid import or import name is not whitelisted, unknown
return Ok(GameplayAffecting::Yes);
return Ok(true);
};
}

Ok(GameplayAffecting::No)
Ok(false)
};

let mod_lowercase_path_map = mod_pak_reader
Expand Down Expand Up @@ -165,7 +164,7 @@ where

let asset_result = check_asset(asset.clone())?;

if asset_result == GameplayAffecting::Yes {
if asset_result {
gameplay_affecting_paths.insert(lower.to_owned());
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Cache {
#[obake(cfg(">=0.0.0"))]
cache: HashMap<String, Box<dyn ModProviderCache>>,
#[obake(cfg(">=0.1.0"))]
gameplay_affecting_cache: HashMap<ModIdentifier, GameplayAffecting>,
gameplay_affecting_cache: HashMap<ModIdentifier, bool>,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -313,15 +313,15 @@ impl ModStore {
.get_version_name(spec, self.cache.clone())
}

pub fn update_gameplay_affecting_status(&self, id: ModIdentifier, stat: GameplayAffecting) {
pub fn update_gameplay_affecting_status(&self, id: ModIdentifier, stat: bool) {
self.cache
.write()
.unwrap()
.gameplay_affecting_cache
.insert(id, stat);
}

pub fn get_gameplay_affecting_status(&self, id: &ModIdentifier) -> Option<GameplayAffecting> {
pub fn get_gameplay_affecting_status(&self, id: &ModIdentifier) -> Option<bool> {
self.cache
.read()
.unwrap()
Expand Down
1 change: 0 additions & 1 deletion src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::{
};

use self::config::ConfigWrapper;
pub(crate) use mint_lib::mod_info::GameplayAffecting;

/// Mod configuration, holds ModSpecification as well as other metadata
#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
Expand Down

0 comments on commit 87f714c

Please sign in to comment.