init
This commit is contained in:
commit
8084ac50b3
1629 changed files with 238620 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
record AddonDescriptor(
|
||||
String id,
|
||||
String name,
|
||||
String version,
|
||||
String description,
|
||||
List<String> authors,
|
||||
String iconPath,
|
||||
int apiVersion,
|
||||
String entrypointDefinition
|
||||
) {
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
public record AddonIssue(
|
||||
String addonId,
|
||||
Severity severity,
|
||||
String message,
|
||||
String detail
|
||||
) {
|
||||
public enum Severity {
|
||||
INFO,
|
||||
WARNING,
|
||||
ERROR
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,540 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualAddon;
|
||||
import dev.loki.lovisual.features.gui.hud.AbstractHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElementRegistry;
|
||||
import dev.loki.lovisual.features.gui.hud.nondraggable.StaticHudElementRegistry;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.features.module.ModuleAutoLoader;
|
||||
import dev.loki.lovisual.features.module.ModuleManager;
|
||||
import dev.loki.lovisual.runtime.ClientRuntime;
|
||||
import dev.loki.lovisual.runtime.RuntimeResumeParticipant;
|
||||
import dev.loki.lovisual.runtime.RuntimeShutdownContext;
|
||||
import dev.loki.lovisual.runtime.RuntimeShutdownParticipant;
|
||||
import dev.loki.lovisual.util.logging.DebugLog;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.metadata.CustomValue;
|
||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum AddonManager {
|
||||
;
|
||||
|
||||
public static final String ADDON_METADATA_KEY = "combatant:addon";
|
||||
|
||||
private static final Map<String, AddonRegistration> ADDONS = new LinkedHashMap<>();
|
||||
private static final Map<String, Boolean> ENABLED_OVERRIDES = new LinkedHashMap<>();
|
||||
private static final Map<String, String> MODULE_OWNERS = new LinkedHashMap<>();
|
||||
private static final Map<String, String> DRAGGABLE_HUD_OWNERS = new LinkedHashMap<>();
|
||||
private static final Map<String, String> STATIC_HUD_OWNERS = new LinkedHashMap<>();
|
||||
private static boolean discovered;
|
||||
private static boolean moduleLoadingPrepared;
|
||||
private static boolean initialized;
|
||||
private static boolean clientReady;
|
||||
|
||||
/**
|
||||
* Discovers enabled addon entrypoints and lets them configure built-in module
|
||||
* exclusions before {@code ModuleAutoLoader} starts instantiating modules.
|
||||
*/
|
||||
public static void prepareModuleLoading() {
|
||||
ensureDiscovered();
|
||||
if (moduleLoadingPrepared) return;
|
||||
moduleLoadingPrepared = true;
|
||||
configureEnabledAddons();
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
if (initialized) return;
|
||||
prepareModuleLoading();
|
||||
if (!ModuleAutoLoader.isDiscoveryFinished()) {
|
||||
return;
|
||||
}
|
||||
reconcileModuleExclusions();
|
||||
initialized = true;
|
||||
initializeEnabledAddons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes addon startup after module configs have been loaded and applied.
|
||||
*/
|
||||
public static void notifyClientReady() {
|
||||
init();
|
||||
if (!initialized) return;
|
||||
clientReady = true;
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
notifyClientReady(registration);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureDiscovered() {
|
||||
if (discovered) return;
|
||||
discovered = true;
|
||||
ENABLED_OVERRIDES.clear();
|
||||
ENABLED_OVERRIDES.putAll(AddonStateStore.loadEnabledOverrides());
|
||||
discoverEntrypoints();
|
||||
}
|
||||
|
||||
public static void registerRuntimeLifecycle() {
|
||||
ClientRuntime.setAddonCounter(AddonManager::activeCount);
|
||||
ClientRuntime.registerParticipant(new RuntimeShutdownParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "addons";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(RuntimeShutdownContext context) {
|
||||
suspendForRuntime(context);
|
||||
}
|
||||
});
|
||||
ClientRuntime.registerResumeParticipant(new RuntimeResumeParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "addons";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(String reason) {
|
||||
resumeAfterRuntime(reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<AddonSnapshot> snapshots() {
|
||||
init();
|
||||
return ADDONS.values().stream()
|
||||
.map(AddonRegistration::snapshot)
|
||||
.sorted(Comparator.comparing(AddonSnapshot::name, String.CASE_INSENSITIVE_ORDER))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static AddonSnapshot snapshot(String id) {
|
||||
init();
|
||||
AddonRegistration registration = ADDONS.get(normalizeId(id));
|
||||
return registration == null ? null : registration.snapshot();
|
||||
}
|
||||
|
||||
public static boolean isActive(String id) {
|
||||
init();
|
||||
AddonRegistration registration = ADDONS.get(normalizeId(id));
|
||||
return registration != null && registration.enabled && registration.status == AddonStatus.ACTIVE;
|
||||
}
|
||||
|
||||
public static List<AddonIssue> scan() {
|
||||
init();
|
||||
List<AddonIssue> out = new ArrayList<>();
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
validateRegistration(registration);
|
||||
out.addAll(registration.issues);
|
||||
}
|
||||
if (out.isEmpty()) {
|
||||
out.add(new AddonIssue("combatant", AddonIssue.Severity.INFO, "No addon errors found", ""));
|
||||
}
|
||||
return List.copyOf(out);
|
||||
}
|
||||
|
||||
public static String moduleProfileOwnerId(String moduleId) {
|
||||
String addonId = MODULE_OWNERS.get(normalizeId(moduleId));
|
||||
return addonId == null ? "module:" + moduleId : "addon:" + addonId + ":module:" + moduleId;
|
||||
}
|
||||
|
||||
public static String draggableHudProfileOwnerId(String elementId) {
|
||||
String addonId = DRAGGABLE_HUD_OWNERS.get(normalizeId(elementId));
|
||||
return addonId == null ? "hud.draggable:" + elementId : "addon:" + addonId + ":hud.draggable:" + elementId;
|
||||
}
|
||||
|
||||
public static String staticHudProfileOwnerId(String elementId) {
|
||||
String addonId = STATIC_HUD_OWNERS.get(normalizeId(elementId));
|
||||
return addonId == null ? "hud.static:" + elementId : "addon:" + addonId + ":hud.static:" + elementId;
|
||||
}
|
||||
|
||||
public static String profileDisplayName(String ownerId, String displayName) {
|
||||
String addonId = addonIdFromProfileOwner(ownerId);
|
||||
if (addonId == null) return displayName;
|
||||
AddonRegistration registration = ADDONS.get(addonId);
|
||||
String addonName = registration == null ? addonId : registration.descriptor.name();
|
||||
return addonName + " / " + displayName;
|
||||
}
|
||||
|
||||
public static String addonIdFromProfileOwner(String ownerId) {
|
||||
if (ownerId == null || !ownerId.startsWith("addon:")) return null;
|
||||
int start = "addon:".length();
|
||||
int end = ownerId.indexOf(':', start);
|
||||
if (end <= start) return null;
|
||||
return normalizeId(ownerId.substring(start, end));
|
||||
}
|
||||
|
||||
public static boolean setEnabled(String id, boolean enabled) {
|
||||
init();
|
||||
String normalizedId = normalizeId(id);
|
||||
AddonRegistration registration = ADDONS.get(normalizedId);
|
||||
if (registration == null) return false;
|
||||
if (registration.enabled == enabled) return true;
|
||||
|
||||
registration.enabled = enabled;
|
||||
registration.restartRequired = false;
|
||||
ENABLED_OVERRIDES.put(normalizedId, enabled);
|
||||
AddonStateStore.saveEnabledOverrides(ENABLED_OVERRIDES);
|
||||
|
||||
if (enabled) {
|
||||
if (!registration.moduleConfigurationApplied) {
|
||||
configureAddonModules(registration);
|
||||
}
|
||||
if (!registration.initialized) {
|
||||
initializeAddon(registration);
|
||||
} else {
|
||||
resumeRuntimeContributions(registration);
|
||||
resumeAddon(registration, "enabled by user");
|
||||
if (registration.status != AddonStatus.ERROR) {
|
||||
registration.status = AddonStatus.ACTIVE;
|
||||
}
|
||||
}
|
||||
if (clientReady) {
|
||||
notifyClientReady(registration);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
registration.restartRequired = !registration.disabledBuiltInModules.isEmpty();
|
||||
if (!registration.initialized) {
|
||||
registration.status = AddonStatus.DISABLED;
|
||||
return true;
|
||||
}
|
||||
|
||||
suspendRuntimeContributions(registration);
|
||||
suspendAddon(registration, "disabled by user");
|
||||
registration.status = AddonStatus.DISABLED;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int activeCount() {
|
||||
int count = 0;
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.status == AddonStatus.ACTIVE) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static void discoverEntrypoints() {
|
||||
for (var entrypoint : FabricLoader.getInstance()
|
||||
.getEntrypointContainers(LoVisualAddon.ENTRYPOINT_KEY, LoVisualAddon.class)) {
|
||||
ModMetadata metadata = entrypoint.getProvider().getMetadata();
|
||||
String id = normalizeId(metadata.getId());
|
||||
AddonDescriptor descriptor = descriptor(metadata, entrypoint.getDefinition());
|
||||
boolean enabled = ENABLED_OVERRIDES.getOrDefault(id, true);
|
||||
AddonStatus status = enabled ? AddonStatus.DISCOVERED : AddonStatus.DISABLED;
|
||||
AddonRegistration duplicate = ADDONS.get(id);
|
||||
if (duplicate != null) {
|
||||
duplicate.issue(AddonIssue.Severity.ERROR, "Duplicate addon id", metadata.getId());
|
||||
continue;
|
||||
}
|
||||
AddonRegistration registration = new AddonRegistration(descriptor, entrypoint, enabled, status);
|
||||
validateRegistration(registration);
|
||||
ADDONS.put(id, registration);
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureEnabledAddons() {
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.enabled) {
|
||||
configureAddonModules(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureAddonModules(AddonRegistration registration) {
|
||||
if (registration.moduleConfigurationApplied || !registration.enabled || registration.status == AddonStatus.ERROR) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
LoVisualAddon addon = addonInstance(registration);
|
||||
LoVisualModuleLoadContextImpl context = new LoVisualModuleLoadContextImpl(registration);
|
||||
addon.onConfigureModules(context);
|
||||
context.commit();
|
||||
registration.moduleConfigurationApplied = true;
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Module configuration failed", t.toString());
|
||||
DebugLog.error("Addon module configuration failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void reconcileModuleExclusions() {
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.disabledBuiltInModules.isEmpty()) continue;
|
||||
registration.disabledBuiltInModules.removeIf(reference -> {
|
||||
if (ModuleAutoLoader.wasDisableRequestMatched(reference, registration.descriptor.id())) {
|
||||
return false;
|
||||
}
|
||||
registration.issue(
|
||||
AddonIssue.Severity.WARNING,
|
||||
"Built-in module exclusion target was not found",
|
||||
reference
|
||||
);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void initializeEnabledAddons() {
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.enabled && registration.status != AddonStatus.ERROR) {
|
||||
initializeAddon(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initializeAddon(AddonRegistration registration) {
|
||||
if (registration.initialized || !registration.enabled || registration.status == AddonStatus.ERROR) return;
|
||||
if (!registration.moduleConfigurationApplied) {
|
||||
configureAddonModules(registration);
|
||||
if (registration.status == AddonStatus.ERROR) return;
|
||||
}
|
||||
try {
|
||||
LoVisualAddon addon = addonInstance(registration);
|
||||
addon.onInitialize(new LoVisualAddonContextImpl(registration));
|
||||
registration.initialized = true;
|
||||
registration.status = AddonStatus.ACTIVE;
|
||||
DebugLog.info("Addon initialized: %s", registration.descriptor.id());
|
||||
if (clientReady) {
|
||||
notifyClientReady(registration);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Initialization failed", t.toString());
|
||||
DebugLog.error("Addon initialization failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyClientReady(AddonRegistration registration) {
|
||||
if (registration == null
|
||||
|| registration.clientReadyNotified
|
||||
|| !registration.initialized
|
||||
|| !registration.enabled
|
||||
|| registration.status != AddonStatus.ACTIVE) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
registration.addon.onClientReady(
|
||||
new LoVisualAddonRuntimeContextImpl(registration.descriptor.id())
|
||||
);
|
||||
registration.clientReadyNotified = true;
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Client ready callback failed", t.toString());
|
||||
DebugLog.error("Addon client ready callback failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static LoVisualAddon addonInstance(AddonRegistration registration) {
|
||||
LoVisualAddon addon = registration.addon;
|
||||
if (addon == null) {
|
||||
addon = registration.entrypoint.getEntrypoint();
|
||||
registration.addon = addon;
|
||||
}
|
||||
return addon;
|
||||
}
|
||||
|
||||
private static void suspendForRuntime(RuntimeShutdownContext context) {
|
||||
int suspended = 0;
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.addon == null || registration.status != AddonStatus.ACTIVE) continue;
|
||||
try {
|
||||
if (context.jarReplacement()) {
|
||||
shutdownAddon(registration, context.reason());
|
||||
registration.status = AddonStatus.SHUTDOWN;
|
||||
} else {
|
||||
registration.addon.onRuntimeSuspended(
|
||||
new LoVisualAddonRuntimeContextImpl(registration.descriptor.id())
|
||||
);
|
||||
registration.status = AddonStatus.SUSPENDED;
|
||||
}
|
||||
suspended++;
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Runtime suspend failed", t.toString());
|
||||
DebugLog.error("Addon runtime suspend failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
context.increment("addons_suspended", suspended);
|
||||
}
|
||||
|
||||
private static void resumeAfterRuntime(String reason) {
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.addon == null || registration.status != AddonStatus.SUSPENDED || !registration.enabled) {
|
||||
continue;
|
||||
}
|
||||
resumeAddon(registration, reason);
|
||||
if (registration.status != AddonStatus.ERROR) {
|
||||
registration.status = AddonStatus.ACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void suspendAddon(AddonRegistration registration, String reason) {
|
||||
if (registration.addon == null) return;
|
||||
try {
|
||||
registration.addon.onRuntimeSuspended(new LoVisualAddonRuntimeContextImpl(registration.descriptor.id()));
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Runtime suspend failed", t.toString());
|
||||
DebugLog.error("Addon runtime suspend failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void resumeAddon(AddonRegistration registration, String reason) {
|
||||
if (registration.addon == null) return;
|
||||
try {
|
||||
registration.addon.onRuntimeResumed(new LoVisualAddonRuntimeContextImpl(registration.descriptor.id()));
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Runtime resume failed", t.toString());
|
||||
DebugLog.error("Addon runtime resume failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void shutdownAddon(AddonRegistration registration, String reason) {
|
||||
if (registration.addon == null) return;
|
||||
try {
|
||||
registration.addon.onShutdown(new LoVisualAddonRuntimeContextImpl(registration.descriptor.id()));
|
||||
} catch (Throwable t) {
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Shutdown failed", t.toString());
|
||||
DebugLog.error("Addon shutdown failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void suspendRuntimeContributions(AddonRegistration registration) {
|
||||
registration.suspendedModules.clear();
|
||||
registration.suspendedDraggableHudElements.clear();
|
||||
registration.suspendedStaticHudElements.clear();
|
||||
for (String id : registration.modules) {
|
||||
Module module = ModuleManager.get(id);
|
||||
if (module != null) {
|
||||
registration.suspendedModules.put(id, module.isEnabled());
|
||||
ModuleManager.setRuntimeEnabledTransient(id, false);
|
||||
}
|
||||
}
|
||||
for (String id : registration.draggableHudElements) {
|
||||
DraggableHudElement element = DraggableHudElementRegistry.getById(id);
|
||||
if (element != null) {
|
||||
registration.suspendedDraggableHudElements.put(id, element.isEnabled());
|
||||
element.setRuntimeEnabledTransient(false);
|
||||
}
|
||||
}
|
||||
for (String id : registration.staticHudElements) {
|
||||
AbstractHudElement element = StaticHudElementRegistry.getById(id);
|
||||
if (element != null) {
|
||||
registration.suspendedStaticHudElements.put(id, element.isEnabled());
|
||||
element.setRuntimeEnabledTransient(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void resumeRuntimeContributions(AddonRegistration registration) {
|
||||
for (String id : registration.modules) {
|
||||
Boolean enabled = registration.suspendedModules.get(id);
|
||||
if (enabled != null) {
|
||||
ModuleManager.setRuntimeEnabledTransient(id, enabled);
|
||||
}
|
||||
}
|
||||
for (String id : registration.draggableHudElements) {
|
||||
Boolean enabled = registration.suspendedDraggableHudElements.get(id);
|
||||
DraggableHudElement element = DraggableHudElementRegistry.getById(id);
|
||||
if (enabled != null && element != null) {
|
||||
element.setRuntimeEnabledTransient(enabled);
|
||||
}
|
||||
}
|
||||
for (String id : registration.staticHudElements) {
|
||||
Boolean enabled = registration.suspendedStaticHudElements.get(id);
|
||||
AbstractHudElement element = StaticHudElementRegistry.getById(id);
|
||||
if (enabled != null && element != null) {
|
||||
element.setRuntimeEnabledTransient(enabled);
|
||||
}
|
||||
}
|
||||
registration.suspendedModules.clear();
|
||||
registration.suspendedDraggableHudElements.clear();
|
||||
registration.suspendedStaticHudElements.clear();
|
||||
}
|
||||
|
||||
static void noteModuleOwner(String addonId, String moduleId) {
|
||||
if (moduleId != null && !moduleId.isBlank()) {
|
||||
MODULE_OWNERS.put(normalizeId(moduleId), normalizeId(addonId));
|
||||
}
|
||||
}
|
||||
|
||||
static void noteDraggableHudOwner(String addonId, String elementId) {
|
||||
if (elementId != null && !elementId.isBlank()) {
|
||||
DRAGGABLE_HUD_OWNERS.put(normalizeId(elementId), normalizeId(addonId));
|
||||
}
|
||||
}
|
||||
|
||||
static void noteStaticHudOwner(String addonId, String elementId) {
|
||||
if (elementId != null && !elementId.isBlank()) {
|
||||
STATIC_HUD_OWNERS.put(normalizeId(elementId), normalizeId(addonId));
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateRegistration(AddonRegistration registration) {
|
||||
if (registration.descriptor.apiVersion() != LoVisualAddon.API_VERSION) {
|
||||
registration.issue(
|
||||
AddonIssue.Severity.WARNING,
|
||||
"Addon API version differs from client API",
|
||||
"addon=" + registration.descriptor.apiVersion() + ", client=" + LoVisualAddon.API_VERSION
|
||||
);
|
||||
}
|
||||
if (registration.descriptor.iconPath() == null || registration.descriptor.iconPath().isBlank()) {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Addon icon is missing", "Add icon in fabric.mod.json");
|
||||
}
|
||||
if (registration.descriptor.entrypointDefinition() == null
|
||||
|| registration.descriptor.entrypointDefinition().isBlank()) {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Entrypoint definition is unavailable", "");
|
||||
}
|
||||
}
|
||||
|
||||
private static AddonDescriptor descriptor(ModMetadata metadata, String entrypointDefinition) {
|
||||
List<String> authors = metadata.getAuthors().stream()
|
||||
.map(person -> person.getName() == null ? "" : person.getName())
|
||||
.filter(name -> !name.isBlank())
|
||||
.toList();
|
||||
return new AddonDescriptor(
|
||||
normalizeId(metadata.getId()),
|
||||
blankFallback(metadata.getName(), metadata.getId()),
|
||||
String.valueOf(metadata.getVersion()),
|
||||
metadata.getDescription() == null ? "" : metadata.getDescription(),
|
||||
authors,
|
||||
metadata.getIconPath(64).or(() -> metadata.getIconPath(32)).orElse(""),
|
||||
apiVersion(metadata),
|
||||
entrypointDefinition
|
||||
);
|
||||
}
|
||||
|
||||
private static int apiVersion(ModMetadata metadata) {
|
||||
CustomValue value = metadata.getCustomValue(ADDON_METADATA_KEY);
|
||||
if (value == null || value.getType() != CustomValue.CvType.OBJECT) return LoVisualAddon.API_VERSION;
|
||||
CustomValue api = value.getAsObject().get("api");
|
||||
if (api == null || api.getType() != CustomValue.CvType.NUMBER) return LoVisualAddon.API_VERSION;
|
||||
return api.getAsNumber().intValue();
|
||||
}
|
||||
|
||||
private static String blankFallback(String value, String fallback) {
|
||||
return value == null || value.isBlank() ? fallback : value;
|
||||
}
|
||||
|
||||
private static String normalizeId(String id) {
|
||||
return id == null ? "" : id.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualAddon;
|
||||
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class AddonRegistration {
|
||||
final AddonDescriptor descriptor;
|
||||
final EntrypointContainer<LoVisualAddon> entrypoint;
|
||||
final List<String> modules = new ArrayList<>();
|
||||
final List<String> disabledBuiltInModules = new ArrayList<>();
|
||||
final List<String> draggableHudElements = new ArrayList<>();
|
||||
final List<String> staticHudElements = new ArrayList<>();
|
||||
final List<String> commands = new ArrayList<>();
|
||||
final List<String> clickGuiSections = new ArrayList<>();
|
||||
final List<String> moduleExtensions = new ArrayList<>();
|
||||
final List<String> irisPatchManifests = new ArrayList<>();
|
||||
final List<String> renderCallbacks = new ArrayList<>();
|
||||
final List<String> postProcessPasses = new ArrayList<>();
|
||||
final List<AddonIssue> issues = new ArrayList<>();
|
||||
final Map<String, Boolean> suspendedModules = new LinkedHashMap<>();
|
||||
final Map<String, Boolean> suspendedDraggableHudElements = new LinkedHashMap<>();
|
||||
final Map<String, Boolean> suspendedStaticHudElements = new LinkedHashMap<>();
|
||||
LoVisualAddon addon;
|
||||
boolean moduleConfigurationApplied;
|
||||
boolean initialized;
|
||||
boolean clientReadyNotified;
|
||||
AddonStatus status;
|
||||
boolean enabled;
|
||||
boolean restartRequired;
|
||||
|
||||
AddonRegistration(AddonDescriptor descriptor,
|
||||
EntrypointContainer<LoVisualAddon> entrypoint,
|
||||
boolean enabled,
|
||||
AddonStatus status) {
|
||||
this.descriptor = descriptor;
|
||||
this.entrypoint = entrypoint;
|
||||
this.enabled = enabled;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
AddonSnapshot snapshot() {
|
||||
return new AddonSnapshot(
|
||||
descriptor.id(),
|
||||
descriptor.name(),
|
||||
descriptor.version(),
|
||||
descriptor.description(),
|
||||
descriptor.authors(),
|
||||
descriptor.iconPath(),
|
||||
descriptor.apiVersion(),
|
||||
status,
|
||||
enabled,
|
||||
restartRequired,
|
||||
modules.size(),
|
||||
draggableHudElements.size(),
|
||||
staticHudElements.size(),
|
||||
commands.size(),
|
||||
clickGuiSections.size(),
|
||||
moduleExtensions.size(),
|
||||
irisPatchManifests.size(),
|
||||
List.copyOf(issues)
|
||||
);
|
||||
}
|
||||
|
||||
void issue(AddonIssue.Severity severity, String message, String detail) {
|
||||
issues.add(new AddonIssue(descriptor.id(), severity, message, detail));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualPostProcessCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualPostProcessContext;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderContext;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderStage;
|
||||
import dev.loki.lovisual.features.module.HudPhase;
|
||||
import dev.loki.lovisual.features.module.WorldPhase;
|
||||
import dev.loki.lovisual.render.engine.postprocess.PostProcessManager;
|
||||
import dev.loki.lovisual.render.engine.postprocess.PostProcessPass;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer2D;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer3D;
|
||||
import dev.loki.lovisual.render.engine.text.TextRenderer;
|
||||
import dev.loki.lovisual.util.logging.DebugLog;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum AddonRenderPipelineManager {
|
||||
;
|
||||
|
||||
private static final Map<LoVisualRenderStage, List<RegisteredRenderCallback>> CALLBACKS =
|
||||
new EnumMap<>(LoVisualRenderStage.class);
|
||||
|
||||
static {
|
||||
for (LoVisualRenderStage stage : LoVisualRenderStage.values()) {
|
||||
CALLBACKS.put(stage, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized boolean register(String addonId,
|
||||
String callbackId,
|
||||
LoVisualRenderStage stage,
|
||||
LoVisualRenderCallback callback) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
String normalizedCallbackId = normalize(callbackId);
|
||||
if (normalizedAddonId.isBlank() || normalizedCallbackId.isBlank() || stage == null || callback == null) {
|
||||
return false;
|
||||
}
|
||||
List<RegisteredRenderCallback> callbacks = CALLBACKS.get(stage);
|
||||
for (RegisteredRenderCallback registered : callbacks) {
|
||||
if (registered.addonId().equals(normalizedAddonId) && registered.callbackId().equals(normalizedCallbackId)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
callbacks.add(new RegisteredRenderCallback(normalizedAddonId, normalizedCallbackId, callback));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean hasActiveCallbacks(LoVisualRenderStage stage) {
|
||||
if (stage == null) return false;
|
||||
List<RegisteredRenderCallback> callbacks;
|
||||
synchronized (AddonRenderPipelineManager.class) {
|
||||
callbacks = List.copyOf(CALLBACKS.get(stage));
|
||||
}
|
||||
for (RegisteredRenderCallback callback : callbacks) {
|
||||
if (AddonManager.isActive(callback.addonId())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean registerPostProcess(String addonId,
|
||||
String passId,
|
||||
PostProcessPass.Phase phase,
|
||||
int priority,
|
||||
LoVisualPostProcessCallback callback) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
String normalizedPassId = normalize(passId);
|
||||
if (normalizedAddonId.isBlank() || normalizedPassId.isBlank() || phase == null || callback == null) {
|
||||
return false;
|
||||
}
|
||||
PostProcessManager.register(new AddonPostProcessPass(normalizedAddonId, normalizedPassId, phase, priority, callback));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void render2D(LoVisualRenderStage stage,
|
||||
HudPhase hudPhase,
|
||||
Renderer2D renderer,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor guiContext,
|
||||
float tickDelta) {
|
||||
render(stage, hudPhase, null, renderer, null, null, textRenderer, guiContext, null, tickDelta);
|
||||
}
|
||||
|
||||
public static void render3D(LoVisualRenderStage stage,
|
||||
WorldPhase worldPhase,
|
||||
Renderer3D renderer,
|
||||
Renderer3D depthRenderer,
|
||||
PoseStack poseStack,
|
||||
float tickDelta) {
|
||||
render(stage, null, worldPhase, null, renderer, depthRenderer, null, null, poseStack, tickDelta);
|
||||
}
|
||||
|
||||
public static synchronized void unregisterAddon(String addonId) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
for (List<RegisteredRenderCallback> callbacks : CALLBACKS.values()) {
|
||||
callbacks.removeIf(callback -> callback.addonId().equals(normalizedAddonId));
|
||||
}
|
||||
}
|
||||
|
||||
private static void render(LoVisualRenderStage stage,
|
||||
HudPhase hudPhase,
|
||||
WorldPhase worldPhase,
|
||||
Renderer2D renderer2D,
|
||||
Renderer3D renderer3D,
|
||||
Renderer3D depthRenderer3D,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor guiContext,
|
||||
PoseStack poseStack,
|
||||
float tickDelta) {
|
||||
List<RegisteredRenderCallback> callbacks;
|
||||
synchronized (AddonRenderPipelineManager.class) {
|
||||
callbacks = List.copyOf(CALLBACKS.get(stage));
|
||||
}
|
||||
for (RegisteredRenderCallback registered : callbacks) {
|
||||
if (!AddonManager.isActive(registered.addonId())) continue;
|
||||
try {
|
||||
registered.callback().render(new LoVisualRenderContext(
|
||||
registered.addonId(),
|
||||
registered.callbackId(),
|
||||
stage,
|
||||
hudPhase,
|
||||
worldPhase,
|
||||
renderer2D,
|
||||
renderer3D,
|
||||
depthRenderer3D,
|
||||
textRenderer,
|
||||
guiContext,
|
||||
poseStack,
|
||||
tickDelta
|
||||
));
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Render callback failed: addon=%s id=%s",
|
||||
t, registered.addonId(), registered.callbackId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalize(String id) {
|
||||
return id == null ? "" : id.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private record RegisteredRenderCallback(String addonId,
|
||||
String callbackId,
|
||||
LoVisualRenderCallback callback) {
|
||||
}
|
||||
|
||||
private record AddonPostProcessPass(String addonId,
|
||||
String passId,
|
||||
PostProcessPass.Phase phase,
|
||||
int priority,
|
||||
LoVisualPostProcessCallback callback) implements PostProcessPass {
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return AddonManager.isActive(addonId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean render(GpuTextureView src, GpuTextureView dst, float tickDelta) {
|
||||
if (!isActive()) return false;
|
||||
try {
|
||||
return callback.render(new LoVisualPostProcessContext(addonId, passId, phase, src, dst, tickDelta));
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Post-process callback failed: addon=%s id=%s", t, addonId, passId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Phase getPhase() {
|
||||
return phase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record AddonSnapshot(
|
||||
String id,
|
||||
String name,
|
||||
String version,
|
||||
String description,
|
||||
List<String> authors,
|
||||
String iconPath,
|
||||
int apiVersion,
|
||||
AddonStatus status,
|
||||
boolean enabled,
|
||||
boolean restartRequired,
|
||||
int modules,
|
||||
int draggableHudElements,
|
||||
int staticHudElements,
|
||||
int commands,
|
||||
int clickGuiSections,
|
||||
int moduleExtensions,
|
||||
int irisPatchManifests,
|
||||
List<AddonIssue> issues
|
||||
) {
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class AddonStateStore {
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private AddonStateStore() {
|
||||
}
|
||||
|
||||
static Map<String, Boolean> loadEnabledOverrides() {
|
||||
Path file = stateFile();
|
||||
if (!Files.isRegularFile(file)) return new HashMap<>();
|
||||
try (Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
|
||||
State state = GSON.fromJson(reader, State.class);
|
||||
if (state == null || state.enabled == null) return new HashMap<>();
|
||||
return new HashMap<>(state.enabled);
|
||||
} catch (Throwable ignored) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
static void saveEnabledOverrides(Map<String, Boolean> enabled) {
|
||||
Path file = stateFile();
|
||||
try {
|
||||
Files.createDirectories(file.getParent());
|
||||
State state = new State();
|
||||
state.enabled = new HashMap<>(enabled);
|
||||
try (Writer writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) {
|
||||
GSON.toJson(state, writer);
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static Path stateFile() {
|
||||
return FabricLoader.getInstance().getConfigDir()
|
||||
.resolve("combatant")
|
||||
.resolve("addons.json");
|
||||
}
|
||||
|
||||
private static final class State {
|
||||
Map<String, Boolean> enabled = new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
public enum AddonStatus {
|
||||
DISCOVERED,
|
||||
DISABLED,
|
||||
ACTIVE,
|
||||
SUSPENDED,
|
||||
ERROR,
|
||||
SHUTDOWN
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.clickgui.LoVisualClickGuiSection;
|
||||
import dev.loki.lovisual.api.v0.clickgui.LoVisualClickGuiRenderContext;
|
||||
import dev.loki.lovisual.features.gui.clickgui.ClickGuiRenderer;
|
||||
import dev.loki.lovisual.features.gui.clickgui.sections.ClickGuiSection;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ClickGuiSectionManager {
|
||||
;
|
||||
|
||||
private static final Map<String, Entry> SECTIONS = new LinkedHashMap<>();
|
||||
|
||||
public static synchronized boolean register(String addonId,
|
||||
String sectionId,
|
||||
String label,
|
||||
LoVisualClickGuiSection section) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
String normalizedSectionId = normalize(sectionId);
|
||||
if (normalizedAddonId.isBlank() || normalizedSectionId.isBlank() || section == null) {
|
||||
return false;
|
||||
}
|
||||
String id = normalizedAddonId + ":" + normalizedSectionId;
|
||||
if (SECTIONS.containsKey(id)) {
|
||||
return false;
|
||||
}
|
||||
String title = label == null || label.isBlank() ? normalizedSectionId : label.trim();
|
||||
SECTIONS.put(id, new Entry(
|
||||
normalizedAddonId,
|
||||
id,
|
||||
normalizedSectionId,
|
||||
title,
|
||||
new AddonSectionAdapter(section)
|
||||
));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized void unregisterAddon(String addonId) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
SECTIONS.entrySet().removeIf(entry -> {
|
||||
if (!entry.getValue().addonId().equals(normalizedAddonId)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
entry.getValue().section().onDeselected();
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public static synchronized List<Entry> sections() {
|
||||
return SECTIONS.values().stream()
|
||||
.filter(entry -> AddonManager.isActive(entry.addonId()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static String normalize(String value) {
|
||||
return value == null ? "" : value.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public record Entry(String addonId,
|
||||
String id,
|
||||
String localId,
|
||||
String label,
|
||||
ClickGuiSection section) {
|
||||
}
|
||||
|
||||
private record AddonSectionAdapter(LoVisualClickGuiSection section) implements ClickGuiSection {
|
||||
@Override
|
||||
public void layout(float x, float y, float w, float h) {
|
||||
section.layout(x, y, w, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float mouseX, float mouseY) {
|
||||
section.render(
|
||||
new LoVisualClickGuiRenderContext(
|
||||
ClickGuiRenderer.currentRenderer(),
|
||||
ClickGuiRenderer.getInterRegular(),
|
||||
ClickGuiRenderer.getInterMedium()
|
||||
),
|
||||
mouseX,
|
||||
mouseY
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderGlassPass(float alphaFactor) {
|
||||
section.renderGlassPass(alphaFactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(float mouseX, float mouseY, int button) {
|
||||
return section.mousePressed(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(float mouseX, float mouseY, int button) {
|
||||
section.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(float mouseX, float mouseY, double amount) {
|
||||
return section.mouseScrolled(mouseX, mouseY, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return section.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char chr, int modifiers) {
|
||||
return section.charTyped(chr, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelected() {
|
||||
section.onSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeselected() {
|
||||
section.onDeselected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return section.isVisible();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualAddonContext;
|
||||
import dev.loki.lovisual.api.v0.clickgui.LoVisualClickGuiSection;
|
||||
import dev.loki.lovisual.api.v0.client.LoVisualClientApi;
|
||||
import dev.loki.lovisual.api.v0.module.LoVisualModuleExtension;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualPostProcessCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderStage;
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandManager;
|
||||
import dev.loki.lovisual.features.gui.hud.AbstractHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElementRegistry;
|
||||
import dev.loki.lovisual.features.gui.hud.nondraggable.StaticHudElementRegistry;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.render.engine.pipeline.CombatantRenderPipelines;
|
||||
import dev.loki.lovisual.render.engine.postprocess.PostProcessPass;
|
||||
import dev.loki.lovisual.render.iris.patch.ShaderPatchEngine;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
final class LoVisualAddonContextImpl implements LoVisualAddonContext {
|
||||
private final AddonRegistration registration;
|
||||
|
||||
LoVisualAddonContextImpl(AddonRegistration registration) {
|
||||
this.registration = registration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addonId() {
|
||||
return registration.descriptor.id();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoVisualClientApi client() {
|
||||
return LoVisualClientApi.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModContainer modContainer() {
|
||||
return registration.entrypoint.getProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path gameDir() {
|
||||
return FabricLoader.getInstance().getGameDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path configDir() {
|
||||
return FabricLoader.getInstance().getConfigDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path addonConfigDir() {
|
||||
return configDir().resolve("lovisual").resolve("addons").resolve(addonId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModule(Module module) {
|
||||
if (module == null) return;
|
||||
module.postInit();
|
||||
registration.modules.add(module.name());
|
||||
AddonManager.noteModuleOwner(addonId(), module.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDraggableHudElement(DraggableHudElement element) {
|
||||
if (element == null) return;
|
||||
DraggableHudElementRegistry.register(element);
|
||||
registration.draggableHudElements.add(element.getId());
|
||||
AddonManager.noteDraggableHudOwner(addonId(), element.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStaticHudElement(AbstractHudElement element) {
|
||||
if (element == null) return;
|
||||
StaticHudElementRegistry.register(element);
|
||||
registration.staticHudElements.add(element.getId());
|
||||
AddonManager.noteStaticHudOwner(addonId(), element.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommand(ClientCommand command) {
|
||||
if (command == null) return;
|
||||
CommandManager.register(new AddonClientCommand(addonId(), command));
|
||||
registration.commands.add(command.metadata().id());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerClickGuiSection(String sectionId, String label, LoVisualClickGuiSection section) {
|
||||
if (ClickGuiSectionManager.register(addonId(), sectionId, label, section)) {
|
||||
registration.clickGuiSections.add(sectionId);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "ClickGui section registration failed", sectionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModuleExtension(String moduleId, LoVisualModuleExtension extension) {
|
||||
if (ModuleExtensionManager.register(addonId(), moduleId, extension)) {
|
||||
registration.moduleExtensions.add(moduleId);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Module extension target is unavailable", moduleId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIrisShaderPatchManifest(String manifestResourcePath) {
|
||||
if (ShaderPatchEngine.registerManifestResource(manifestResourcePath)) {
|
||||
registration.irisPatchManifests.add(manifestResourcePath);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Iris patch manifest registration failed", manifestResourcePath);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRenderCallback(String callbackId, LoVisualRenderStage stage, LoVisualRenderCallback callback) {
|
||||
if (AddonRenderPipelineManager.register(addonId(), callbackId, stage, callback)) {
|
||||
registration.renderCallbacks.add(stage.name().toLowerCase(java.util.Locale.ROOT) + ":" + callbackId);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Render callback registration failed", callbackId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPostProcessPass(String passId,
|
||||
PostProcessPass.Phase phase,
|
||||
int priority,
|
||||
LoVisualPostProcessCallback callback) {
|
||||
if (AddonRenderPipelineManager.registerPostProcess(addonId(), passId, phase, priority, callback)) {
|
||||
registration.postProcessPasses.add(phase.name().toLowerCase(java.util.Locale.ROOT) + ":" + passId);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Post-process registration failed", passId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderPipeline registerRenderPipeline(RenderPipeline pipeline) {
|
||||
if (pipeline == null) return null;
|
||||
RenderPipeline registered = CombatantRenderPipelines.registerAddonPipeline(pipeline);
|
||||
registration.renderCallbacks.add("pipeline:" + pipeline.getLocation());
|
||||
return registered;
|
||||
}
|
||||
|
||||
private record AddonClientCommand(String addonId, ClientCommand delegate) implements ClientCommand {
|
||||
@Override
|
||||
public dev.loki.lovisual.features.command.CommandMetadata metadata() {
|
||||
return delegate.metadata();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public String name() {
|
||||
return delegate.name();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public java.util.List<String> aliases() {
|
||||
return delegate.aliases();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public String usage() {
|
||||
return delegate.usage();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public String description() {
|
||||
return delegate.description();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return AddonManager.isActive(addonId) && delegate.isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<String> suggest(dev.loki.lovisual.features.command.CommandContext ctx, int argIndex, String token) {
|
||||
return delegate.suggest(ctx, argIndex, token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(dev.loki.lovisual.features.command.CommandContext ctx) {
|
||||
return isAvailable() && delegate.execute(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualAddonRuntimeContext;
|
||||
import dev.loki.lovisual.api.v0.client.LoVisualClientApi;
|
||||
|
||||
final class LoVisualAddonRuntimeContextImpl implements LoVisualAddonRuntimeContext {
|
||||
private final String addonId;
|
||||
|
||||
LoVisualAddonRuntimeContextImpl(String addonId) {
|
||||
this.addonId = addonId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addonId() {
|
||||
return addonId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoVisualClientApi client() {
|
||||
return LoVisualClientApi.get();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualModuleLoadContext;
|
||||
import dev.loki.lovisual.features.module.ModuleAutoLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
final class LoVisualModuleLoadContextImpl implements LoVisualModuleLoadContext {
|
||||
private final AddonRegistration registration;
|
||||
private final List<String> pendingExclusions = new ArrayList<>();
|
||||
|
||||
LoVisualModuleLoadContextImpl(AddonRegistration registration) {
|
||||
this.registration = registration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addonId() {
|
||||
return registration.descriptor.id();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disableBuiltInModule(String moduleReference) {
|
||||
String reference = moduleReference == null ? "" : moduleReference.trim();
|
||||
if (reference.isEmpty()) return false;
|
||||
|
||||
if (!ModuleAutoLoader.acceptsDisableRequests()) {
|
||||
noteRestartRequired(reference);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pendingExclusions.contains(reference)) {
|
||||
pendingExclusions.add(reference);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void commit() {
|
||||
for (String reference : pendingExclusions) {
|
||||
if (!registration.disabledBuiltInModules.contains(reference)) {
|
||||
registration.disabledBuiltInModules.add(reference);
|
||||
}
|
||||
if (!ModuleAutoLoader.requestDisable(reference, addonId())) {
|
||||
noteRestartRequired(reference);
|
||||
}
|
||||
}
|
||||
pendingExclusions.clear();
|
||||
}
|
||||
|
||||
private void noteRestartRequired(String reference) {
|
||||
if (!registration.disabledBuiltInModules.contains(reference)) {
|
||||
registration.disabledBuiltInModules.add(reference);
|
||||
}
|
||||
registration.restartRequired = true;
|
||||
registration.issue(
|
||||
AddonIssue.Severity.WARNING,
|
||||
"Built-in module exclusion requires restart",
|
||||
reference
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.module.ModuleExtensionContext;
|
||||
import dev.loki.lovisual.config.SettingDef;
|
||||
import dev.loki.lovisual.config.values.ConfigValue;
|
||||
import dev.loki.lovisual.config.values.ModeValue;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
|
||||
final class ModuleExtensionContextImpl implements ModuleExtensionContext {
|
||||
private final String addonId;
|
||||
private final Module module;
|
||||
|
||||
ModuleExtensionContextImpl(String addonId, Module module) {
|
||||
this.addonId = addonId;
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addonId() {
|
||||
return addonId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String moduleId() {
|
||||
return module.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module module() {
|
||||
return module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSetting(SettingDef setting) {
|
||||
module.addExtensionSetting(setting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigValue<?> getConfigValue(String configName) {
|
||||
return module.getConfigValue(configName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addModeOption(String configName, String option) {
|
||||
ConfigValue<?> value = getConfigValue(configName);
|
||||
return value instanceof ModeValue mode && mode.addOption(option);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.module.LoVisualModuleExtension;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.features.module.ModuleManager;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer2D;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer3D;
|
||||
import dev.loki.lovisual.render.engine.text.TextRenderer;
|
||||
import dev.loki.lovisual.util.logging.DebugLog;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ModuleExtensionManager {
|
||||
;
|
||||
|
||||
private static final Map<String, List<RegisteredExtension>> EXTENSIONS = new LinkedHashMap<>();
|
||||
|
||||
public static boolean register(String addonId, String moduleId, LoVisualModuleExtension extension) {
|
||||
if (extension == null || moduleId == null || moduleId.isBlank()) return false;
|
||||
Module module = ModuleManager.get(moduleId);
|
||||
if (module == null) {
|
||||
DebugLog.warn("[Addons] Module extension target missing: addon=%s module=%s", addonId, moduleId);
|
||||
return false;
|
||||
}
|
||||
String normalized = normalize(moduleId);
|
||||
RegisteredExtension registered = new RegisteredExtension(addonId, extension);
|
||||
EXTENSIONS.computeIfAbsent(normalized, ignored -> new ArrayList<>()).add(registered);
|
||||
try {
|
||||
extension.onRegister(new ModuleExtensionContextImpl(addonId, module));
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Module extension registration failed: %s", t, normalized);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int count() {
|
||||
int count = 0;
|
||||
for (List<RegisteredExtension> list : EXTENSIONS.values()) {
|
||||
count += list.size();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static boolean beforeEnable(Module module) {
|
||||
return all(module, extension -> extension.beforeEnable(module));
|
||||
}
|
||||
|
||||
public static void afterEnable(Module module) {
|
||||
each(module, extension -> extension.afterEnable(module));
|
||||
}
|
||||
|
||||
public static boolean beforeDisable(Module module) {
|
||||
return all(module, extension -> extension.beforeDisable(module));
|
||||
}
|
||||
|
||||
public static void afterDisable(Module module) {
|
||||
each(module, extension -> extension.afterDisable(module));
|
||||
}
|
||||
|
||||
public static boolean beforeTick(Module module) {
|
||||
return all(module, extension -> extension.beforeTick(module));
|
||||
}
|
||||
|
||||
public static void afterTick(Module module) {
|
||||
each(module, extension -> extension.afterTick(module));
|
||||
}
|
||||
|
||||
public static boolean beforeFrame(Module module, float frameDeltaTicks) {
|
||||
return all(module, extension -> extension.beforeFrame(module, frameDeltaTicks));
|
||||
}
|
||||
|
||||
public static void afterFrame(Module module, float frameDeltaTicks) {
|
||||
each(module, extension -> extension.afterFrame(module, frameDeltaTicks));
|
||||
}
|
||||
|
||||
public static boolean beforeHudRender(Module module,
|
||||
Renderer2D renderer,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor ctx,
|
||||
float tickDelta) {
|
||||
return all(module, extension -> extension.beforeHudRender(module, renderer, textRenderer, ctx, tickDelta));
|
||||
}
|
||||
|
||||
public static void afterHudRender(Module module,
|
||||
Renderer2D renderer,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor ctx,
|
||||
float tickDelta) {
|
||||
each(module, extension -> extension.afterHudRender(module, renderer, textRenderer, ctx, tickDelta));
|
||||
}
|
||||
|
||||
public static boolean beforeWorldRender(Module module,
|
||||
Renderer3D renderer,
|
||||
Renderer3D depthRenderer,
|
||||
float tickDelta) {
|
||||
return all(module, extension -> extension.beforeWorldRender(module, renderer, depthRenderer, tickDelta));
|
||||
}
|
||||
|
||||
public static void afterWorldRender(Module module,
|
||||
Renderer3D renderer,
|
||||
Renderer3D depthRenderer,
|
||||
float tickDelta) {
|
||||
each(module, extension -> extension.afterWorldRender(module, renderer, depthRenderer, tickDelta));
|
||||
}
|
||||
|
||||
private static boolean all(Module module, ExtensionBooleanCall call) {
|
||||
List<RegisteredExtension> extensions = extensions(module);
|
||||
if (extensions.isEmpty()) return true;
|
||||
boolean proceed = true;
|
||||
for (RegisteredExtension registered : extensions) {
|
||||
if (!AddonManager.isActive(registered.addonId())) continue;
|
||||
try {
|
||||
proceed &= call.invoke(registered.extension());
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Module extension hook failed: addon=%s module=%s",
|
||||
t, registered.addonId(), module == null ? "" : module.name());
|
||||
}
|
||||
}
|
||||
return proceed;
|
||||
}
|
||||
|
||||
private static void each(Module module, ExtensionVoidCall call) {
|
||||
List<RegisteredExtension> extensions = extensions(module);
|
||||
if (extensions.isEmpty()) return;
|
||||
for (RegisteredExtension registered : extensions) {
|
||||
if (!AddonManager.isActive(registered.addonId())) continue;
|
||||
try {
|
||||
call.invoke(registered.extension());
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Module extension hook failed: addon=%s module=%s",
|
||||
t, registered.addonId(), module == null ? "" : module.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<RegisteredExtension> extensions(Module module) {
|
||||
if (module == null) return List.of();
|
||||
List<RegisteredExtension> list = EXTENSIONS.get(normalize(module.name()));
|
||||
return list == null ? List.of() : List.copyOf(list);
|
||||
}
|
||||
|
||||
private static String normalize(String id) {
|
||||
return id == null ? "" : id.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface ExtensionBooleanCall {
|
||||
boolean invoke(LoVisualModuleExtension extension);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface ExtensionVoidCall {
|
||||
void invoke(LoVisualModuleExtension extension);
|
||||
}
|
||||
|
||||
private record RegisteredExtension(String addonId, LoVisualModuleExtension extension) {
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue