diff --git a/.github/scripts/thunderstore_bundle.js b/.github/scripts/thunderstore_bundle.js index 962981e2d..14e4a7334 100644 --- a/.github/scripts/thunderstore_bundle.js +++ b/.github/scripts/thunderstore_bundle.js @@ -11,33 +11,39 @@ import { statSync, } from "fs"; import { join } from "path"; -import fgrpkg from "@terascope/fetch-github-release"; -const downloadRelease = fgrpkg; -import json2toml from "json2toml"; import child_process from "child_process"; import { zip } from "zip-a-folder"; -import fsepkg from "fs-extra"; -const move = fsepkg.move; +import fsepkg, { copy } from "fs-extra"; const remove = fsepkg.remove; import * as core from "@actions/core"; // Setting it so that it's consistent with installs from thunderstore const NEBULA_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerMod"; +const NEBULA_API_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerModApi"; const DIST_FOLDER = "dist"; const DIST_RELEASE_FOLDER = join(DIST_FOLDER, "release"); -const DIST_NEBULA_FOLDER = join(DIST_RELEASE_FOLDER, "nebula"); -const DIST_TSTORE_CLI_FOLDER = join(DIST_RELEASE_FOLDER, "tstore-cli"); -const DIST_TSTORE_CLI_EXE_PATH = join(DIST_TSTORE_CLI_FOLDER, "tstore-cli.exe"); -const DIST_TSTORE_CLI_CONFIG_PATH = join( - DIST_TSTORE_CLI_FOLDER, - "publish.toml" +const DIST_NEBULA_FOLDER = join( + DIST_RELEASE_FOLDER, + NEBULA_RELEASE_FOLDER_NAME +); +const DIST_NEBULA_API_FOLDER = join( + DIST_RELEASE_FOLDER, + NEBULA_API_RELEASE_FOLDER_NAME ); +const DIST_TSTORE_CLI_FOLDER = join("Libs", "tcli"); +const DIST_TSTORE_CLI_EXE_PATH = join(DIST_TSTORE_CLI_FOLDER, "tcli.exe"); const PLUGIN_INFO_PATH = "NebulaPatcher\\PluginInfo.cs"; +const API_PLUGIN_INFO_PATH = "NebulaAPI\\NebulaModAPI.cs"; const pluginInfo = getPluginInfo(); +const apiPluginInfo = getApiPluginInfo(); const TSTORE_ARCHIVE_PATH = join( DIST_RELEASE_FOLDER, "nebula-thunderstore.zip" ); +const TSTORE_API_ARCHIVE_PATH = join( + DIST_RELEASE_FOLDER, + "nebula-api-thunderstore.zip" +); const GH_ARCHIVE_PATH = join( DIST_RELEASE_FOLDER, "Nebula_" + pluginInfo.version + ".zip" @@ -48,29 +54,40 @@ const CHANGELOG_PATH = "CHANGELOG.md"; async function main() { if (!existsSync(DIST_NEBULA_FOLDER)) { - throw DIST_NEBULA_FOLDER + " does not exist"; + let err = DIST_NEBULA_FOLDER + " does not exist"; + core.setFailed(err); + throw err; } - if (!existsSync(DIST_TSTORE_CLI_FOLDER)) { - mkdirSync(DIST_TSTORE_CLI_FOLDER, { recursive: true }); + if (!existsSync(DIST_NEBULA_API_FOLDER)) { + let err = DIST_NEBUDIST_NEBULA_API_FOLDERLA_FOLDER + " does not exist"; + core.setFailed(err); + throw err; } try { generateReleaseBody(); } catch (err) { core.setFailed(err); + throw err; } generateManifest(); + generateApiManifest(); copyIcon(); + copyApiIcon(); copyReadme(); + copyApiReadme(); appendChangelog(); + appendApiChangelog(); copyLicenses(); + copyApiLicense(); await createTStoreArchive(); + await createTStoreApiArchive(); await createGHArchive(); - await doTStoreRelease(); + uploadToTStore(); } function getPluginInfo() { @@ -83,13 +100,29 @@ function getPluginInfo() { }; } +function getApiPluginInfo() { + const pluginInfoRaw = readFileSync(API_PLUGIN_INFO_PATH).toString("utf-8"); + const versionInfoRaw = readFileSync( + join("NebulaAPI", "version.json") + ).toString("utf-8"); + return { + name: pluginInfoRaw.match(/API_NAME = "(.*)";/)[1], + id: pluginInfoRaw.match(/API_GUID = "(.*)";/)[1], + version: JSON.parse(versionInfoRaw).version, + }; +} + function generateManifest() { const manifest = { name: pluginInfo.name, description: "With this mod you will be able to play with your friends in the same game!", version_number: pluginInfo.version, - dependencies: ["xiaoye97-BepInEx-5.4.11", "PhantomGamers-IlLine-1.0.0"], + dependencies: [ + "xiaoye97-BepInEx-5.4.11", + `nebula-${apiPluginInfo.name}-${apiPluginInfo.version}`, + "PhantomGamers-IlLine-1.0.0", + ], website_url: "https://github.com/hubastard/nebula", }; writeFileSync( @@ -98,14 +131,41 @@ function generateManifest() { ); } +function generateApiManifest() { + const manifest = { + name: apiPluginInfo.name, + description: "API for other mods to work with the Nebula Multiplayer Mod", + version_number: apiPluginInfo.version, + website_url: "https://github.com/hubastard/nebula", + }; + writeFileSync( + join(DIST_NEBULA_API_FOLDER, "manifest.json"), + JSON.stringify(manifest, null, 2) + ); +} + function copyIcon() { copyFileSync(MOD_ICON_PATH, join(DIST_NEBULA_FOLDER, "icon.png")); } +function copyApiIcon() { + copyFileSync( + join("NebulaAPI", "icon.png"), + join(DIST_NEBULA_API_FOLDER, "icon.png") + ); +} + function copyReadme() { copyFileSync(README_PATH, join(DIST_NEBULA_FOLDER, README_PATH)); } +function copyApiReadme() { + copyFileSync( + join("NebulaAPI", README_PATH), + join(DIST_NEBULA_API_FOLDER, README_PATH) + ); +} + function appendChangelog() { appendFileSync( join(DIST_NEBULA_FOLDER, README_PATH), @@ -113,11 +173,22 @@ function appendChangelog() { ); } +function appendApiChangelog() { + appendFileSync( + join(DIST_NEBULA_API_FOLDER, README_PATH), + "\n" + readFileSync(join("NebulaAPI", CHANGELOG_PATH)) + ); +} + function copyLicenses() { copyFileSync("LICENSE", join(DIST_NEBULA_FOLDER, "nebula.LICENSE")); copyFolderContent("Licenses", DIST_NEBULA_FOLDER); } +function copyApiLicense() { + copyFileSync("LICENSE", join(DIST_NEBULA_API_FOLDER, "nebula.LICENSE")); +} + function copyFolderContent(src, dst, excludedExts) { readdirSync(src).forEach((file) => { const srcPath = join(src, file); @@ -138,54 +209,6 @@ function copyFolderContent(src, dst, excludedExts) { }); } -async function doTStoreRelease() { - const user = "Windows10CE"; - const repo = "tstore-cli"; - const outputdir = DIST_TSTORE_CLI_FOLDER; - const leaveZipped = false; - const disableLogging = false; - - // Define a function to filter releases. - function filterRelease(release) { - // Filter out prereleases. - return release.prerelease === false; - } - - // Define a function to filter assets. - function filterAsset(asset) { - // Select assets that contain the string 'windows'. - return asset.name.includes("tstore-cli.exe"); - } - - try { - await downloadRelease( - user, - repo, - outputdir, - filterRelease, - filterAsset, - leaveZipped, - disableLogging - ); - console.log("Successfully downloaded tstore-cli.exe"); - await new Promise((r) => setTimeout(r, 2000)); - generateTStoreConfig(); - uploadToTStore(); - } catch (err) { - console.error(err.message); - } -} - -function generateTStoreConfig() { - const config = { - author: "nebula", - communities: ["dyson-sphere-program"], - nsfw: false, - zip: TSTORE_ARCHIVE_PATH, - }; - writeFileSync(DIST_TSTORE_CLI_CONFIG_PATH, json2toml(config)); -} - function generateReleaseBody() { const changelog = readFileSync(CHANGELOG_PATH, "utf-8"); const versionRegExp = new RegExp( @@ -215,37 +238,46 @@ function generateReleaseBody() { join(DIST_RELEASE_FOLDER, "BODY.md"), "# Alpha Version " + currentVersion + "\n\n### Changes\n" + body ); - - console.log(body); } async function createTStoreArchive() { await zip(DIST_NEBULA_FOLDER, TSTORE_ARCHIVE_PATH); } +async function createTStoreApiArchive() { + await zip(DIST_NEBULA_API_FOLDER, TSTORE_API_ARCHIVE_PATH); +} + async function createGHArchive() { // Ensure contents are within subfolder in zip - await move( + await copy( DIST_NEBULA_FOLDER, join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME) ); - await zip(join(DIST_FOLDER, "tmp"), GH_ARCHIVE_PATH); - await move( - join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME), - DIST_NEBULA_FOLDER + await copy( + DIST_NEBULA_API_FOLDER, + join(DIST_FOLDER, "tmp", NEBULA_API_RELEASE_FOLDER_NAME) ); + await zip(join(DIST_FOLDER, "tmp"), GH_ARCHIVE_PATH); await remove(join(DIST_FOLDER, "tmp")); } function uploadToTStore() { - child_process.execSync( - DIST_TSTORE_CLI_EXE_PATH + - " publish --config " + - DIST_TSTORE_CLI_CONFIG_PATH, - function (err) { - console.error(err); - } - ); + try { + child_process.execSync( + `"${DIST_TSTORE_CLI_EXE_PATH}" publish --file "${TSTORE_ARCHIVE_PATH}" --token "${process.env.TSTORE_TOKEN}" --use-session-auth` + ); + } catch (error) { + console.error(`Thunderstore upload failed for ${TSTORE_ARCHIVE_PATH}`); + } + + try { + child_process.execSync( + `"${DIST_TSTORE_CLI_EXE_PATH}" publish --file "${TSTORE_API_ARCHIVE_PATH}" --token "${process.env.TSTORE_TOKEN}" --use-session-auth` + ); + } catch (error) { + console.error(`Thunderstore upload failed for ${TSTORE_API_ARCHIVE_PATH}`); + } } main(); diff --git a/.github/workflows/build-winx64.yml b/.github/workflows/build-winx64.yml index a549645f4..2806b4264 100644 --- a/.github/workflows/build-winx64.yml +++ b/.github/workflows/build-winx64.yml @@ -29,7 +29,7 @@ jobs: - name: Clear output directory in DSP files # We use SilentlyContinue here because it errors out if the folder does not exist otherwise - run: rm -R -ErrorAction SilentlyContinue "dist\release\nebula" + run: rm -R -ErrorAction SilentlyContinue "dist" - name: Add remote build identifier run: New-Item -Name .remoteBuild -ItemType File -force @@ -50,4 +50,4 @@ jobs: with: # Artifact name name: build-artifacts-${{ matrix.configuration }} - path: dist\release\nebula + path: dist\release diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 4a7960cf6..f7d9664bd 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -46,10 +46,10 @@ jobs: - name: Clear output directory in DSP files # We use SilentlyContinue here because it errors out if the folder does not exist otherwise - run : rm -R -ErrorAction SilentlyContinue "${{ env.NEBULA_FOLDER }}" + run : rm -R -ErrorAction SilentlyContinue "dist" - name: Add remote build identifier - run: copy /b /Y NUL .remoteBuild + run: New-Item -Name .remoteBuild -ItemType File -force # Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild - name: Setup MSBuild.exe @@ -91,7 +91,13 @@ jobs: - uses: actions/upload-artifact@v2.2.4 with: name: nebula-thunderstore - path: ${{ env.DIST_RELEASE_FOLDER }}nebula + path: ${{ env.DIST_RELEASE_FOLDER }}nebula-NebulaMultiplayerMod + + # Upload the API thunderstore artifact (in case automatic upload fails) + - uses: actions/upload-artifact@v2.2.4 + with: + name: nebula-api-thunderstore + path: ${{ env.DIST_RELEASE_FOLDER }}nebula-NebulaMultiplayerModApi # Create release - uses: hubastard/release-action@v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4804171de..06eeb8775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ## Changelog +0.5.0: + +- Added API that enables other mods to sync over multiplayer! (Big thanks to @kremnev8!) +- Fixed a bug that caused sorters to break when a client built a belt under preexisting sorters. +- Fixed a bug that resulted in the client getting an error after disconnecting from a game that the host left. +- Refactored session architecture (big changes to codebase but should be seamless to users) + 0.4.0: - Nebula now supports DSP version 0.8.20.7962+ @@ -20,4 +27,4 @@ 0.2.0: -- initial release on thunderstore \ No newline at end of file +- initial release on thunderstore diff --git a/Directory.Build.props b/Directory.Build.props index e37af8085..e15a63ce0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -10,9 +10,9 @@ C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\ $([MSBuild]::EnsureTrailingSlash('$(DSPGameDir)')) - $(DSPGameDir)BepInEx\plugins\Nebula\ + $(DSPGameDir)BepInEx\plugins\nebula-NebulaMultiplayerMod\ $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)')) - $(PropSheetPath)dist\release\nebula + $(PropSheetPath)dist\release\nebula-NebulaMultiplayerMod\ @@ -21,7 +21,6 @@ true $(PluginOutputDirectory) - $(OutputPath) net472 7.3 true @@ -31,15 +30,21 @@ portable true + + + $(OutputPath)..\nebula-NebulaMultiplayerModApi + - - + + + + diff --git a/Libs/tcli/CommandLine.dll b/Libs/tcli/CommandLine.dll new file mode 100644 index 000000000..af18229e9 Binary files /dev/null and b/Libs/tcli/CommandLine.dll differ diff --git a/Libs/tcli/Crayon.dll b/Libs/tcli/Crayon.dll new file mode 100644 index 000000000..a2a3e4b04 Binary files /dev/null and b/Libs/tcli/Crayon.dll differ diff --git a/Libs/tcli/Tommy.dll b/Libs/tcli/Tommy.dll new file mode 100644 index 000000000..3e50217d8 Binary files /dev/null and b/Libs/tcli/Tommy.dll differ diff --git a/Libs/tcli/tcli.deps.json b/Libs/tcli/tcli.deps.json new file mode 100644 index 000000000..c678feb01 --- /dev/null +++ b/Libs/tcli/tcli.deps.json @@ -0,0 +1,74 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v5.0/win-x64", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v5.0": {}, + ".NETCoreApp,Version=v5.0/win-x64": { + "tcli/0.0.1": { + "dependencies": { + "CommandLineParser": "2.8.0", + "Crayon": "2.0.60", + "Tommy": "2.0.0" + }, + "runtime": { + "tcli.dll": {} + } + }, + "CommandLineParser/2.8.0": { + "runtime": { + "lib/netstandard2.0/CommandLine.dll": { + "assemblyVersion": "2.8.0.0", + "fileVersion": "2.8.0.0" + } + } + }, + "Crayon/2.0.60": { + "runtime": { + "lib/netstandard2.0/Crayon.dll": { + "assemblyVersion": "2.0.60.0", + "fileVersion": "2.0.60.0" + } + } + }, + "Tommy/2.0.0": { + "runtime": { + "lib/netstandard2.0/Tommy.dll": { + "assemblyVersion": "2.0.0.0", + "fileVersion": "2.0.0.0" + } + } + } + } + }, + "libraries": { + "tcli/0.0.1": { + "type": "project", + "serviceable": false, + "sha512": "" + }, + "CommandLineParser/2.8.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-eco2HlKQBY4Joz9odHigzGpVzv6pjsXnY5lziioMveQxr+i2Z7xYcIOMeZTgYiqnMtMAbXMXsVhrNfWO5vJS8Q==", + "path": "commandlineparser/2.8.0", + "hashPath": "commandlineparser.2.8.0.nupkg.sha512" + }, + "Crayon/2.0.60": { + "type": "package", + "serviceable": true, + "sha512": "sha512-pqARvOP7vsCdTa/nMB115Ci0eSbkhKDqBbWxsVgLUoJUejgFE9qJ+N5j44nmqHCRP2ohuGgFQnCD9Iodhm+DSA==", + "path": "crayon/2.0.60", + "hashPath": "crayon.2.0.60.nupkg.sha512" + }, + "Tommy/2.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-5XBermvZiJPubbS6njoNRcq8+hy+iKQ21xArDznKoc/nvSLyF/va4PCwHHMLESf2SVFUbadP9zl0KqQzHHhVPg==", + "path": "tommy/2.0.0", + "hashPath": "tommy.2.0.0.nupkg.sha512" + } + } +} \ No newline at end of file diff --git a/Libs/tcli/tcli.dll b/Libs/tcli/tcli.dll new file mode 100644 index 000000000..3c5b587aa Binary files /dev/null and b/Libs/tcli/tcli.dll differ diff --git a/Libs/tcli/tcli.exe b/Libs/tcli/tcli.exe new file mode 100644 index 000000000..32adcf551 Binary files /dev/null and b/Libs/tcli/tcli.exe differ diff --git a/Libs/tcli/tcli.runtimeconfig.json b/Libs/tcli/tcli.runtimeconfig.json new file mode 100644 index 000000000..d54914baf --- /dev/null +++ b/Libs/tcli/tcli.runtimeconfig.json @@ -0,0 +1,12 @@ +{ + "runtimeOptions": { + "tfm": "net5.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "5.0.0" + }, + "configProperties": { + "System.Reflection.Metadata.MetadataUpdater.IsSupported": false + } + } +} \ No newline at end of file diff --git a/Nebula.sln b/Nebula.sln index 56bb35da9..afe0d2be1 100644 --- a/Nebula.sln +++ b/Nebula.sln @@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "websocket-sharp", "dep\webs EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NebulaNetwork", "NebulaNetwork\NebulaNetwork.csproj", "{36A3D8AE-2A0A-4A1F-8A65-4FB61B01F779}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NebulaAPI", "NebulaAPI\NebulaAPI.csproj", "{B59DB3BB-DBA2-42AF-B4F1-32A9A6A273D2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +51,10 @@ Global {47B9362C-E91B-4AE4-979B-7D811AB4D1EA}.Debug|Any CPU.Build.0 = Debug|Any CPU {47B9362C-E91B-4AE4-979B-7D811AB4D1EA}.Release|Any CPU.ActiveCfg = Release|Any CPU {47B9362C-E91B-4AE4-979B-7D811AB4D1EA}.Release|Any CPU.Build.0 = Release|Any CPU + {B59DB3BB-DBA2-42AF-B4F1-32A9A6A273D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B59DB3BB-DBA2-42AF-B4F1-32A9A6A273D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B59DB3BB-DBA2-42AF-B4F1-32A9A6A273D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B59DB3BB-DBA2-42AF-B4F1-32A9A6A273D2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NebulaAPI/CHANGELOG.md b/NebulaAPI/CHANGELOG.md new file mode 100644 index 000000000..0a520df56 --- /dev/null +++ b/NebulaAPI/CHANGELOG.md @@ -0,0 +1,5 @@ +## Changelog + +1.0.0: + +- initial release on thunderstore diff --git a/NebulaModel/DataStructures/CollectionExtensions.cs b/NebulaAPI/DataStructures/CollectionExtensions.cs similarity index 95% rename from NebulaModel/DataStructures/CollectionExtensions.cs rename to NebulaAPI/DataStructures/CollectionExtensions.cs index 96a664193..ca540eeeb 100644 --- a/NebulaModel/DataStructures/CollectionExtensions.cs +++ b/NebulaAPI/DataStructures/CollectionExtensions.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Threading; -namespace NebulaModel.DataStructures +namespace NebulaAPI { public static class CollectionExtensions { diff --git a/NebulaAPI/DataStructures/DataStructureExtenstions.cs b/NebulaAPI/DataStructures/DataStructureExtenstions.cs new file mode 100644 index 000000000..9d8d5c7e1 --- /dev/null +++ b/NebulaAPI/DataStructures/DataStructureExtenstions.cs @@ -0,0 +1,32 @@ +using UnityEngine; + +namespace NebulaAPI +{ + public static class DataStructureExtenstions + { + public static Vector3 ToVector3(this Float3 value) + { + return new Vector3(value.x, value.y, value.z); + } + + public static VectorLF3 ToVectorLF3(this Double3 value) + { + return new VectorLF3(value.x, value.y, value.z); + } + + public static Float3 ToFloat3(this Vector3 value) + { + return new Float3(value.x, value.y, value.z); + } + + public static Quaternion ToQuaternion(this Float4 value) + { + return new Quaternion(value.x, value.y, value.z, value.w); + } + + public static Float4 ToFloat4(this Quaternion value) + { + return new Float4(value.x, value.y, value.z, value.w); + } + } +} \ No newline at end of file diff --git a/NebulaModel/DataStructures/Double3.cs b/NebulaAPI/DataStructures/Double3.cs similarity index 74% rename from NebulaModel/DataStructures/Double3.cs rename to NebulaAPI/DataStructures/Double3.cs index c720d22a2..7706ece86 100644 --- a/NebulaModel/DataStructures/Double3.cs +++ b/NebulaAPI/DataStructures/Double3.cs @@ -1,7 +1,5 @@ -using NebulaModel.Attributes; -using NebulaModel.Networking.Serialization; - -namespace NebulaModel.DataStructures + +namespace NebulaAPI { [RegisterNestedType] public struct Double3 : INetSerializable @@ -17,14 +15,14 @@ public Double3(double x, double y, double z) this.z = z; } - public void Serialize(NetDataWriter writer) + public void Serialize(INetDataWriter writer) { writer.Put(x); writer.Put(y); writer.Put(z); } - public void Deserialize(NetDataReader reader) + public void Deserialize(INetDataReader reader) { x = reader.GetDouble(); y = reader.GetDouble(); diff --git a/NebulaModel/DataStructures/Float3.cs b/NebulaAPI/DataStructures/Float3.cs similarity index 78% rename from NebulaModel/DataStructures/Float3.cs rename to NebulaAPI/DataStructures/Float3.cs index 7db2c58dc..6a3abb723 100644 --- a/NebulaModel/DataStructures/Float3.cs +++ b/NebulaAPI/DataStructures/Float3.cs @@ -1,8 +1,6 @@ -using NebulaModel.Attributes; -using NebulaModel.Networking.Serialization; -using UnityEngine; +using UnityEngine; -namespace NebulaModel.DataStructures +namespace NebulaAPI { [RegisterNestedType] public struct Float3 : INetSerializable @@ -29,14 +27,14 @@ public Color ToColor() return new Color(x, y, z); } - public void Serialize(NetDataWriter writer) + public void Serialize(INetDataWriter writer) { writer.Put(x); writer.Put(y); writer.Put(z); } - public void Deserialize(NetDataReader reader) + public void Deserialize(INetDataReader reader) { x = reader.GetFloat(); y = reader.GetFloat(); diff --git a/NebulaModel/DataStructures/Float4.cs b/NebulaAPI/DataStructures/Float4.cs similarity index 79% rename from NebulaModel/DataStructures/Float4.cs rename to NebulaAPI/DataStructures/Float4.cs index 5db7098ad..e99753e33 100644 --- a/NebulaModel/DataStructures/Float4.cs +++ b/NebulaAPI/DataStructures/Float4.cs @@ -1,8 +1,6 @@ -using NebulaModel.Attributes; -using NebulaModel.Networking.Serialization; -using UnityEngine; +using UnityEngine; -namespace NebulaModel.DataStructures +namespace NebulaAPI { [RegisterNestedType] public struct Float4 : INetSerializable @@ -28,7 +26,7 @@ public Float4(Quaternion value) w = value.w; } - public void Serialize(NetDataWriter writer) + public void Serialize(INetDataWriter writer) { writer.Put(x); writer.Put(y); @@ -36,7 +34,7 @@ public void Serialize(NetDataWriter writer) writer.Put(w); } - public void Deserialize(NetDataReader reader) + public void Deserialize(INetDataReader reader) { x = reader.GetFloat(); y = reader.GetFloat(); diff --git a/NebulaAPI/DataStructures/IMechaData.cs b/NebulaAPI/DataStructures/IMechaData.cs new file mode 100644 index 000000000..274267311 --- /dev/null +++ b/NebulaAPI/DataStructures/IMechaData.cs @@ -0,0 +1,15 @@ +// unset + +namespace NebulaAPI +{ + public interface IMechaData : INetSerializable + { + int SandCount { get; set; } + double CoreEnergy { get; set; } + double ReactorEnergy { get; set; } + StorageComponent Inventory { get; set; } + StorageComponent ReactorStorage { get; set; } + StorageComponent WarpStorage { get; set; } + MechaForge Forge { get; set; } + } +} \ No newline at end of file diff --git a/NebulaAPI/DataStructures/IPlayerTechBonuses.cs b/NebulaAPI/DataStructures/IPlayerTechBonuses.cs new file mode 100644 index 000000000..e58fa887e --- /dev/null +++ b/NebulaAPI/DataStructures/IPlayerTechBonuses.cs @@ -0,0 +1,34 @@ +// unset + +namespace NebulaAPI +{ + public interface IPlayerTechBonuses : INetSerializable + { + double coreEnergyCap { get; } + double corePowerGen { get; } + double reactorPowerGen { get; } + double walkPower { get; } + double jumpEnergy { get; } + double thrustPowerPerAcc { get; } + double warpKeepingPowerPerSpeed { get; } + double warpStartPowerPerSpeed { get; } + double miningPower { get; } + double replicatePower { get; } + double researchPower { get; } + double droneEjectEnergy { get; } + double droneEnergyPerMeter { get; } + int coreLevel { get; } + int thrusterLevel { get; } + float miningSpeed { get; } + float replicateSpeed { get; } + float walkSpeed { get; } + float jumpSpeed { get; } + float maxSailSpeed { get; } + float maxWarpSpeed { get; } + float buildArea { get; } + int droneCount { get; } + float droneSpeed { get; } + int droneMovement { get; } + int inventorySize { get; } + } +} \ No newline at end of file diff --git a/NebulaAPI/GameState/IFactoryManager.cs b/NebulaAPI/GameState/IFactoryManager.cs new file mode 100644 index 000000000..a977cf22b --- /dev/null +++ b/NebulaAPI/GameState/IFactoryManager.cs @@ -0,0 +1,47 @@ +using System; +using UnityEngine; + +namespace NebulaAPI +{ + /// + /// Represents data about factory + /// + public interface IFactoryManager : IDisposable + { + /// + /// Did we receive a packet? + /// + IToggle IsIncomingRequest { get; } + + int PacketAuthor { get; set; } + + int TargetPlanet { get; set; } + + PlanetFactory EventFactory { get; set; } + + /// + /// Request to load planet + /// + void AddPlanetTimer(int planetId); + + void LoadPlanetData(int planetId); + + void UnloadPlanetData(int planetId); + + void InitializePrebuildRequests(); + + void SetPrebuildRequest(int planetId, int prebuildId, ushort playerId); + + bool RemovePrebuildRequest(int planetId, int prebuildId); + + bool ContainsPrebuildRequest(int planetId, int prebuildId); + + int GetNextPrebuildId(int planetId); + + int GetNextPrebuildId(PlanetFactory factory); + + void OnNewSetInserterPickTarget(int objId, int otherObjId, int inserterId, int offset, Vector3 pointPos); + + void OnNewSetInserterInsertTarget(int objId, int otherObjId, int inserterId, int offset, Vector3 pointPos); + } +} \ No newline at end of file diff --git a/NebulaAPI/GameState/ILocalPlayer.cs b/NebulaAPI/GameState/ILocalPlayer.cs new file mode 100644 index 000000000..008d98459 --- /dev/null +++ b/NebulaAPI/GameState/ILocalPlayer.cs @@ -0,0 +1,17 @@ +using System; + +namespace NebulaAPI +{ + /// + /// Represents local player. Allows to send packets. + /// + public interface ILocalPlayer : IDisposable + { + bool IsInitialDataReceived { get; } + bool IsHost { get; } + bool IsClient { get; } + bool IsNewPlayer { get; } + ushort Id { get; } + IPlayerData Data { get; } + } +} \ No newline at end of file diff --git a/NebulaAPI/GameState/IMultiplayerSession.cs b/NebulaAPI/GameState/IMultiplayerSession.cs new file mode 100644 index 000000000..b66a55784 --- /dev/null +++ b/NebulaAPI/GameState/IMultiplayerSession.cs @@ -0,0 +1,11 @@ +namespace NebulaAPI +{ + public interface IMultiplayerSession + { + INetworkProvider Network { get; } + ILocalPlayer LocalPlayer { get; } + IFactoryManager Factories { get; } + + bool IsGameLoaded { get; } + } +} \ No newline at end of file diff --git a/NebulaAPI/GameState/INebulaPlayer.cs b/NebulaAPI/GameState/INebulaPlayer.cs new file mode 100644 index 000000000..78506f47d --- /dev/null +++ b/NebulaAPI/GameState/INebulaPlayer.cs @@ -0,0 +1,13 @@ +namespace NebulaAPI +{ + public interface INebulaPlayer + { + INebulaConnection Connection { get; } + IPlayerData Data { get; } + ushort Id{ get; } + int CurrentResearchId { get; } + long TechProgressContributed { get; } + void SendPacket(T packet) where T : class, new(); + void LoadUserData(IPlayerData data); + } +} \ No newline at end of file diff --git a/NebulaAPI/GameState/INetworkProvider.cs b/NebulaAPI/GameState/INetworkProvider.cs new file mode 100644 index 000000000..f9392e5aa --- /dev/null +++ b/NebulaAPI/GameState/INetworkProvider.cs @@ -0,0 +1,35 @@ +using System; + +namespace NebulaAPI +{ + public interface INetworkProvider : IDisposable + { + /// + /// Send packet to Host (If ran on Client) or all Clients (If ran on Host) + /// + void SendPacket(T packet) where T : class, new(); + /// + /// Send packet to all Clients within current star system + /// + void SendPacketToLocalStar(T packet) where T : class, new(); + /// + /// Send packet to all Clients within current planet + /// + void SendPacketToLocalPlanet(T packet) where T : class, new(); + + /// + /// Send packet to all Clients on a planet + /// + void SendPacketToPlanet(T packet, int planetId) where T : class, new(); + /// + /// Send packet to all Clients within star system + /// + void SendPacketToStar(T packet, int starId) where T : class, new(); + + void SendPacketToStarExclude(T packet, int starId, INebulaConnection exclude) where T : class, new(); + + IPlayerManager PlayerManager { get; } + + void Update(); + } +} \ No newline at end of file diff --git a/NebulaAPI/GameState/IPlayerData.cs b/NebulaAPI/GameState/IPlayerData.cs new file mode 100644 index 000000000..d3d526820 --- /dev/null +++ b/NebulaAPI/GameState/IPlayerData.cs @@ -0,0 +1,19 @@ +namespace NebulaAPI +{ + public interface IPlayerData : INetSerializable + { + string Username { get; set; } + ushort PlayerId { get; set; } + int LocalPlanetId { get; set; } + Float3 MechaColor { get; set; } + Float3 LocalPlanetPosition { get; set; } + Double3 UPosition { get; set; } + Float3 Rotation { get; set; } + Float3 BodyRotation { get; set; } + int LocalStarId { get; set; } + + IMechaData Mecha { get; set; } + + IPlayerData CreateCopyWithoutMechaData(); + } +} \ No newline at end of file diff --git a/NebulaAPI/GameState/IPlayerManager.cs b/NebulaAPI/GameState/IPlayerManager.cs new file mode 100644 index 000000000..82611174b --- /dev/null +++ b/NebulaAPI/GameState/IPlayerManager.cs @@ -0,0 +1,50 @@ +using NebulaAPI; +using System.Collections.Generic; + +namespace NebulaAPI +{ + public interface IPlayerManager + { + Locker GetPendingPlayers(out Dictionary pendingPlayers); + + Locker GetSyncingPlayers(out Dictionary syncingPlayers); + + Locker GetConnectedPlayers(out Dictionary connectedPlayers); + + Locker GetSavedPlayerData(out Dictionary savedPlayerData); + + IPlayerData[] GetAllPlayerDataIncludingHost(); + + INebulaPlayer GetPlayer(INebulaConnection conn); + + INebulaPlayer GetSyncingPlayer(INebulaConnection conn); + + void SendPacketToAllPlayers(T packet) where T : class, new(); + + void SendPacketToLocalStar(T packet) where T : class, new(); + + void SendPacketToLocalPlanet(T packet) where T : class, new(); + + void SendPacketToPlanet(T packet, int planetId) where T : class, new(); + + void SendPacketToStar(T packet, int starId) where T : class, new(); + + void SendPacketToStarExcept(T packet, int starId, INebulaConnection exclude) where T : class, new(); + + void SendRawPacketToStar(byte[] rawPacket, int starId, INebulaConnection sender); + + void SendRawPacketToPlanet(byte[] rawPacket, int planetId, INebulaConnection sender); + + void SendPacketToOtherPlayers(T packet, INebulaPlayer sender) where T : class, new(); + + INebulaPlayer PlayerConnected(INebulaConnection conn); + + void PlayerDisconnected(INebulaConnection conn); + + ushort GetNextAvailablePlayerId(); + + void SendTechRefundPackagesToClients(int techId); + + void UpdateMechaData(IMechaData mechaData, INebulaConnection conn); + } +} diff --git a/NebulaAPI/Interfaces/BinaryInterfaces.cs b/NebulaAPI/Interfaces/BinaryInterfaces.cs new file mode 100644 index 000000000..73b0cca44 --- /dev/null +++ b/NebulaAPI/Interfaces/BinaryInterfaces.cs @@ -0,0 +1,22 @@ +using System; +using System.IO; + +namespace NebulaAPI +{ + /// + /// Provides access to BinaryWriter with LZ4 compression + /// + public interface IWriterProvider : IDisposable + { + BinaryWriter BinaryWriter { get; } + byte[] CloseAndGetBytes(); + } + + /// + /// Provides access to BinaryReader with LZ4 compression + /// + public interface IReaderProvider : IDisposable + { + BinaryReader BinaryReader { get; } + } +} \ No newline at end of file diff --git a/NebulaAPI/Interfaces/IMultiplayerMod.cs b/NebulaAPI/Interfaces/IMultiplayerMod.cs new file mode 100644 index 000000000..56109c543 --- /dev/null +++ b/NebulaAPI/Interfaces/IMultiplayerMod.cs @@ -0,0 +1,22 @@ +using System.IO; + +namespace NebulaAPI +{ + /// + /// Implement this interface to make sure your mod will be the same version on the host + /// + public interface IMultiplayerMod + { + string Version { get; } + bool CheckVersion(string hostVersion, string clientVersion); + } + + /// + /// Implement this interface if you have important settings that clients need to know + /// + public interface IMultiplayerModWithSettings : IMultiplayerMod + { + void Export (BinaryWriter w); + void Import (BinaryReader r); + } +} diff --git a/NebulaAPI/Interfaces/INetSerializable.cs b/NebulaAPI/Interfaces/INetSerializable.cs new file mode 100644 index 000000000..2ae55c1ff --- /dev/null +++ b/NebulaAPI/Interfaces/INetSerializable.cs @@ -0,0 +1,150 @@ +using System; +using System.Net; +using System.Text; + +namespace NebulaAPI +{ + public interface INetSerializable + { + void Serialize(INetDataWriter writer); + void Deserialize(INetDataReader reader); + } + + public interface INetDataWriter + { + void Put(float value); + + void Put(double value); + + void Put(long value); + + void Put(ulong value); + + void Put(int value); + + void Put(uint value); + + void Put(char value); + + void Put(ushort value); + + void Put(short value); + + void Put(sbyte value); + + void Put(byte value); + + void Put(byte[] data, int offset, int length); + + void Put(byte[] data); + + void PutSBytesWithLength(sbyte[] data, int offset, int length); + + void PutSBytesWithLength(sbyte[] data); + + void PutBytesWithLength(byte[] data, int offset, int length); + + void PutBytesWithLength(byte[] data); + + void Put(bool value); + + void PutArray(float[] value); + + void PutArray(double[] value); + + void PutArray(long[] value); + + void PutArray(ulong[] value); + + void PutArray(int[] value); + + void PutArray(uint[] value); + + void PutArray(ushort[] value); + + void PutArray(short[] value); + + void PutArray(bool[] value); + + void PutArray(string[] value); + + void PutArray(string[] value, int maxLength); + + void Put(IPEndPoint endPoint); + + void Put(string value); + + void Put(string value, int maxLength); + + void Put(T obj) where T : INetSerializable; + } + + public interface INetDataReader + { + IPEndPoint GetNetEndPoint(); + + byte GetByte(); + + sbyte GetSByte(); + + bool[] GetBoolArray(); + + ushort[] GetUShortArray(); + + short[] GetShortArray(); + + long[] GetLongArray(); + + ulong[] GetULongArray(); + + int[] GetIntArray(); + + uint[] GetUIntArray(); + + float[] GetFloatArray(); + + double[] GetDoubleArray(); + + string[] GetStringArray(); + + string[] GetStringArray(int maxStringLength); + + bool GetBool(); + + char GetChar(); + + ushort GetUShort(); + + short GetShort(); + + long GetLong(); + + ulong GetULong(); + + int GetInt(); + + uint GetUInt(); + + float GetFloat(); + + double GetDouble(); + + string GetString(int maxLength); + + string GetString(); + + ArraySegment GetRemainingBytesSegment(); + + T Get() where T : INetSerializable, new(); + + byte[] GetRemainingBytes(); + + void GetBytes(byte[] destination, int start, int count); + + void GetBytes(byte[] destination, int count); + + sbyte[] GetSBytesWithLength(); + + byte[] GetBytesWithLength(); + } +} diff --git a/NebulaAPI/Interfaces/IToggle.cs b/NebulaAPI/Interfaces/IToggle.cs new file mode 100644 index 000000000..35f757294 --- /dev/null +++ b/NebulaAPI/Interfaces/IToggle.cs @@ -0,0 +1,10 @@ +using System; + +namespace NebulaAPI +{ + public interface IToggle + { + bool Value { get; } + IDisposable On(); + } +} \ No newline at end of file diff --git a/NebulaAPI/NebulaAPI.csproj b/NebulaAPI/NebulaAPI.csproj new file mode 100644 index 000000000..13a6b34c9 --- /dev/null +++ b/NebulaAPI/NebulaAPI.csproj @@ -0,0 +1,2 @@ + + diff --git a/NebulaAPI/NebulaModAPI.cs b/NebulaAPI/NebulaModAPI.cs new file mode 100644 index 000000000..998828091 --- /dev/null +++ b/NebulaAPI/NebulaModAPI.cs @@ -0,0 +1,141 @@ +using BepInEx; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace NebulaAPI +{ + [BepInPlugin(API_GUID, API_NAME, ThisAssembly.AssemblyFileVersion)] + [BepInDependency(NEBULA_MODID, BepInDependency.DependencyFlags.SoftDependency)] + public class NebulaModAPI : BaseUnityPlugin + { + private static bool nebulaIsInstalled; + + private static Type multiplayer; + + private static Type binaryWriter; + private static Type binaryReader; + + public static readonly List TargetAssemblies = new List(); + + public const string NEBULA_MODID = "dsp.nebula-multiplayer"; + + public const string API_GUID = "dsp.nebula-multiplayer-api"; + public const string API_NAME = "NebulaMultiplayerModApi"; + + public static bool NebulaIsInstalled => nebulaIsInstalled; + + /// + /// Is this session in multiplayer + /// + public static bool IsMultiplayerActive + { + get + { + if (!NebulaIsInstalled) return false; + + return (bool)multiplayer.GetProperty("IsActive").GetValue(null); + } + } + + /// + /// Provides access to MultiplayerSession class + /// + public static IMultiplayerSession MultiplayerSession + { + get + { + if (!NebulaIsInstalled) return null; + + return (IMultiplayerSession) multiplayer.GetProperty("Session").GetValue(null); + } + } + + /// + /// Subscribe to receive event when new multiplayer game is started + /// + public static Action OnMultiplayerGameStarted; + + /// + /// Subscribe to receive event when multiplayer game end + /// + public static Action OnMultiplayerGameEnded; + + /// + /// Subscribe to receive event when a new star starts loaded
+ /// int starIndex - index of star to load + ///
+ public static Action OnStarLoadRequest; + + /// + /// Subscribe to receive event when a new planet starts loaded
+ /// int planetId - id of planet to load + ///
+ public static Action OnPlanetLoadRequest; + + /// + /// Subscribe to receive event when a new planet is finished loading
+ /// int planetId - id of planet to load + ///
+ public static Action OnPlanetLoadFinished; + + private void Awake() + { + nebulaIsInstalled = false; + + foreach (var pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) + { + if (pluginInfo.Value.Metadata.GUID == NEBULA_MODID) + { + nebulaIsInstalled = true; + break; + } + } + + if (!nebulaIsInstalled) return; + + multiplayer = AccessTools.TypeByName("NebulaWorld.Multiplayer"); + + Type binaryUtils = AccessTools.TypeByName("NebulaModel.Networking.BinaryUtils"); + + binaryWriter = binaryUtils.GetNestedType("Writer"); + binaryReader = binaryUtils.GetNestedType("Reader"); + + Logger.LogInfo("Nebula API is ready!"); + } + + public const int PLANET_NONE = -2; + public const int AUTHOR_NONE = -1; + public const int STAR_NONE = -1; + + /// + /// Register all packets within assembly + /// + /// Target assembly + public static void RegisterPackets(Assembly assembly) + { + TargetAssemblies.Add(assembly); + } + + /// + /// Provides access to BinaryWriter with LZ4 compression + /// + public static IWriterProvider GetBinaryWriter() + { + if (!NebulaIsInstalled) return null; + + return (IWriterProvider) binaryWriter.GetConstructor(new Type[0]).Invoke(new object[0]); + } + + /// + /// Provides access to BinaryReader with LZ4 compression + /// + public static IReaderProvider GetBinaryReader(byte[] bytes) + { + if (!NebulaIsInstalled) return null; + + return (IReaderProvider) binaryReader.GetConstructor(new[]{typeof(byte[])}).Invoke(new object[]{bytes}); + } + } +} \ No newline at end of file diff --git a/NebulaAPI/Packets/BasePacketProcessor.cs b/NebulaAPI/Packets/BasePacketProcessor.cs new file mode 100644 index 000000000..066232bcb --- /dev/null +++ b/NebulaAPI/Packets/BasePacketProcessor.cs @@ -0,0 +1,30 @@ +namespace NebulaAPI +{ + /// + /// Describes how to process received packets of type T + /// + /// Packet class + public abstract class BasePacketProcessor + { + /// + /// Is code running on Host + /// + protected bool IsHost; + /// + /// Is code running on Client + /// + protected bool IsClient => !IsHost; + + internal void Initialize(bool isHost) + { + IsHost = isHost; + } + + /// + /// Process packets here + /// + /// Received packet + /// Connection that sent the packet + public abstract void ProcessPacket(T packet, INebulaConnection conn); + } +} \ No newline at end of file diff --git a/NebulaModel/Attributes/HidePacketInDebugLogsAttribute.cs b/NebulaAPI/Packets/HidePacketInDebugLogsAttribute.cs similarity index 84% rename from NebulaModel/Attributes/HidePacketInDebugLogsAttribute.cs rename to NebulaAPI/Packets/HidePacketInDebugLogsAttribute.cs index 7b37910e8..b3a3a3415 100644 --- a/NebulaModel/Attributes/HidePacketInDebugLogsAttribute.cs +++ b/NebulaAPI/Packets/HidePacketInDebugLogsAttribute.cs @@ -1,6 +1,6 @@ using System; -namespace NebulaModel.Attributes +namespace NebulaAPI { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)] public class HidePacketInDebugLogsAttribute : Attribute { } diff --git a/NebulaAPI/Packets/INebulaConnection.cs b/NebulaAPI/Packets/INebulaConnection.cs new file mode 100644 index 000000000..94c7a1d5b --- /dev/null +++ b/NebulaAPI/Packets/INebulaConnection.cs @@ -0,0 +1,7 @@ +namespace NebulaAPI +{ + public interface INebulaConnection + { + void SendPacket(T packet) where T : class, new(); + } +} \ No newline at end of file diff --git a/NebulaAPI/Packets/RegisterNestedTypeAttribute.cs b/NebulaAPI/Packets/RegisterNestedTypeAttribute.cs new file mode 100644 index 000000000..ed1cf53f8 --- /dev/null +++ b/NebulaAPI/Packets/RegisterNestedTypeAttribute.cs @@ -0,0 +1,10 @@ +using System; + +namespace NebulaAPI +{ + /// + /// Registers custom data structure serializer. Make sure to register your assembly using NebulaModAPI.RegisterPackets + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)] + public class RegisterNestedTypeAttribute : Attribute { } +} diff --git a/NebulaAPI/Packets/RegisterPacketProcessorAttribute.cs b/NebulaAPI/Packets/RegisterPacketProcessorAttribute.cs new file mode 100644 index 000000000..c229a7f12 --- /dev/null +++ b/NebulaAPI/Packets/RegisterPacketProcessorAttribute.cs @@ -0,0 +1,10 @@ +using System; + +namespace NebulaAPI +{ + /// + /// Registers packet processors. Make sure to register your assembly using NebulaModAPI.RegisterPackets + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class RegisterPacketProcessorAttribute : Attribute { } +} diff --git a/NebulaAPI/README.md b/NebulaAPI/README.md new file mode 100644 index 000000000..928e4c700 --- /dev/null +++ b/NebulaAPI/README.md @@ -0,0 +1,17 @@ +# Nebula Multiplayer API + +API for [Nebula multiplayer mod](https://dsp.thunderstore.io/package/nebula/NebulaMultiplayerMod/). This API allows mod developers to support Nebula. You can find setting up guide, examples and documentation [here](https://github.com/hubastard/nebula/wiki) + +# FAQ + +## Where can I get help using the API? + +Please join our [Discord Server](https://discord.gg/UHeB2QvgDa) and ask your question in the `General` channel. We have a really nice community that will be able to answer your questions. + +## How can I contribute? + +Please join our [Discord Server](https://discord.gg/UHeB2QvgDa) to ask if someone is already working on the task that you want to do. Once, you are done with your modification, simply submit a pull request. Contribution documentation can be found here: [Wiki](https://github.com/hubastard/nebula/wiki/Setting-up-a-development-environment). + +## How can I support the team? + +If you like what we do and would like to support us, you can donate through our [Patreon](https://www.patreon.com/nebula_mod_team). Thanks for the support <3 \ No newline at end of file diff --git a/NebulaAPI/icon.png b/NebulaAPI/icon.png new file mode 100644 index 000000000..63056101e Binary files /dev/null and b/NebulaAPI/icon.png differ diff --git a/NebulaAPI/version.json b/NebulaAPI/version.json new file mode 100644 index 000000000..c2143a858 --- /dev/null +++ b/NebulaAPI/version.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", + "version": "1.0.0", + "assemblyVersion": { + "precision": "build" + }, + "gitCommitIdShortFixedLength": 7, + "publicReleaseRefSpec": [ + "^refs/tags/v\\d+\\.\\d+" + ], + "release": { + "versionIncrement": "build", + "firstUnstableTag": "" + } +} diff --git a/NebulaModel/Attributes/RegisterNestedTypeAttribute.cs b/NebulaModel/Attributes/RegisterNestedTypeAttribute.cs deleted file mode 100644 index 4fdc41a21..000000000 --- a/NebulaModel/Attributes/RegisterNestedTypeAttribute.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; - -namespace NebulaModel.Attributes -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)] - public class RegisterNestedTypeAttribute : Attribute { } -} diff --git a/NebulaModel/Attributes/RegisterPacketProcessorAttribute.cs b/NebulaModel/Attributes/RegisterPacketProcessorAttribute.cs deleted file mode 100644 index 729568d8e..000000000 --- a/NebulaModel/Attributes/RegisterPacketProcessorAttribute.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; - -namespace NebulaModel.Attributes -{ - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - public class RegisterPacketProcessorAttribute : Attribute { } -} diff --git a/NebulaModel/DataStructures/DataStructureExtensions.cs b/NebulaModel/DataStructures/DataStructureExtensions.cs index 2f170ca24..2552f8104 100644 --- a/NebulaModel/DataStructures/DataStructureExtensions.cs +++ b/NebulaModel/DataStructures/DataStructureExtensions.cs @@ -2,33 +2,8 @@ namespace NebulaModel.DataStructures { - public static class DataStructureExtensions + public static class AnimationStateExtensions { - public static Vector3 ToVector3(this Float3 value) - { - return new Vector3(value.x, value.y, value.z); - } - - public static VectorLF3 ToVectorLF3(this Double3 value) - { - return new VectorLF3(value.x, value.y, value.z); - } - - public static Float3 ToFloat3(this Vector3 value) - { - return new Float3(value.x, value.y, value.z); - } - - public static Quaternion ToQuaternion(this Float4 value) - { - return new Quaternion(value.x, value.y, value.z, value.w); - } - - public static Float4 ToFloat4(this Quaternion value) - { - return new Float4(value.x, value.y, value.z, value.w); - } - public static NebulaAnimationState ToNebula(this AnimationState state) { return new NebulaAnimationState() diff --git a/NebulaModel/DataStructures/GameState.cs b/NebulaModel/DataStructures/GameState.cs index b001c8f66..2d2e549e5 100644 --- a/NebulaModel/DataStructures/GameState.cs +++ b/NebulaModel/DataStructures/GameState.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking.Serialization; namespace NebulaModel.DataStructures @@ -15,13 +15,13 @@ public GameState(long timestamp, long gameTick) this.gameTick = gameTick; } - public void Serialize(NetDataWriter writer) + public void Serialize(INetDataWriter writer) { writer.Put(timestamp); writer.Put(gameTick); } - public void Deserialize(NetDataReader reader) + public void Deserialize(INetDataReader reader) { timestamp = reader.GetLong(); gameTick = reader.GetLong(); diff --git a/NebulaModel/DataStructures/MechaData.cs b/NebulaModel/DataStructures/MechaData.cs index f607eece8..74e5f6fa0 100644 --- a/NebulaModel/DataStructures/MechaData.cs +++ b/NebulaModel/DataStructures/MechaData.cs @@ -1,5 +1,4 @@ -using NebulaModel.Attributes; -using NebulaModel.Networking.Serialization; +using NebulaAPI; using NebulaModel.Packets.Players; using System.Collections.Generic; using System.IO; @@ -7,7 +6,7 @@ namespace NebulaModel.DataStructures { [RegisterNestedType] - public class MechaData : INetSerializable + public class MechaData : IMechaData { public int SandCount { get; set; } public double CoreEnergy { get; set; } @@ -40,7 +39,7 @@ public MechaData(int sandCount, double coreEnergy, double reactorEnergy, Storage this.TechBonuses = new PlayerTechBonuses(); } - public void Serialize(NetDataWriter writer) + public void Serialize(INetDataWriter writer) { TechBonuses.Serialize(writer); writer.Put(SandCount); @@ -65,7 +64,7 @@ public void Serialize(NetDataWriter writer) } } - public void Deserialize(NetDataReader reader) + public void Deserialize(INetDataReader reader) { TechBonuses = new PlayerTechBonuses(); Inventory = new StorageComponent(4); diff --git a/NebulaModel/DataStructures/NebulaAnimationState.cs b/NebulaModel/DataStructures/NebulaAnimationState.cs index a3d90d623..7db917c02 100644 --- a/NebulaModel/DataStructures/NebulaAnimationState.cs +++ b/NebulaModel/DataStructures/NebulaAnimationState.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking.Serialization; namespace NebulaModel.DataStructures @@ -10,14 +10,14 @@ public struct NebulaAnimationState : INetSerializable public float Speed { get; set; } public bool Enabled { get; set; } - public void Serialize(NetDataWriter writer) + public void Serialize(INetDataWriter writer) { writer.Put(Weight); writer.Put(Speed); writer.Put(Enabled); } - public void Deserialize(NetDataReader reader) + public void Deserialize(INetDataReader reader) { Weight = reader.GetFloat(); Speed = reader.GetFloat(); diff --git a/NebulaModel/DataStructures/NetDataReaderExtensions.cs b/NebulaModel/DataStructures/NetDataReaderExtensions.cs index f817873a8..8d99f78e1 100644 --- a/NebulaModel/DataStructures/NetDataReaderExtensions.cs +++ b/NebulaModel/DataStructures/NetDataReaderExtensions.cs @@ -1,24 +1,25 @@ -using NebulaModel.Networking.Serialization; +using NebulaAPI; +using NebulaModel.Networking.Serialization; namespace NebulaModel.DataStructures { public static class NetDataReaderExtensions { - public static Float3 GetFloat3(this NetDataReader reader) + public static Float3 GetFloat3(this INetDataReader reader) { Float3 value = new Float3(); value.Deserialize(reader); return value; } - public static Float4 GetFloat4(this NetDataReader reader) + public static Float4 GetFloat4(this INetDataReader reader) { Float4 value = new Float4(); value.Deserialize(reader); return value; } - public static Double3 GetDouble3(this NetDataReader reader) + public static Double3 GetDouble3(this INetDataReader reader) { Double3 value = new Double3(); value.Deserialize(reader); diff --git a/NebulaModel/DataStructures/PlayerData.cs b/NebulaModel/DataStructures/PlayerData.cs index 1f8943cfb..453541c31 100644 --- a/NebulaModel/DataStructures/PlayerData.cs +++ b/NebulaModel/DataStructures/PlayerData.cs @@ -1,10 +1,10 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking.Serialization; namespace NebulaModel.DataStructures { [RegisterNestedType] - public class PlayerData : INetSerializable + public class PlayerData : IPlayerData { public string Username { get; set; } public ushort PlayerId { get; set; } @@ -14,7 +14,7 @@ public class PlayerData : INetSerializable public Double3 UPosition { get; set; } public Float3 Rotation { get; set; } public Float3 BodyRotation { get; set; } - public MechaData Mecha { get; set; } + public IMechaData Mecha { get; set; } public int LocalStarId { get; set; } public PlayerData() { } @@ -31,7 +31,7 @@ public PlayerData() { } Mecha = new MechaData(); } - public void Serialize(NetDataWriter writer) + public void Serialize(INetDataWriter writer) { writer.Put(Username); writer.Put(PlayerId); @@ -44,7 +44,7 @@ public void Serialize(NetDataWriter writer) Mecha.Serialize(writer); } - public void Deserialize(NetDataReader reader) + public void Deserialize(INetDataReader reader) { Username = reader.GetString(); PlayerId = reader.GetUShort(); @@ -58,7 +58,7 @@ public void Deserialize(NetDataReader reader) Mecha.Deserialize(reader); } - public PlayerData CreateCopyWithoutMechaData() + public IPlayerData CreateCopyWithoutMechaData() { return new PlayerData(PlayerId, LocalPlanetId, MechaColor, Username, LocalPlanetPosition, UPosition, Rotation, BodyRotation); } diff --git a/NebulaModel/DataStructures/ToggleSwitch.cs b/NebulaModel/DataStructures/ToggleSwitch.cs index dd4966f7e..cfb9422fd 100644 --- a/NebulaModel/DataStructures/ToggleSwitch.cs +++ b/NebulaModel/DataStructures/ToggleSwitch.cs @@ -1,9 +1,10 @@ -using System; +using NebulaAPI; +using System; using System.Threading; namespace NebulaModel.DataStructures { - public sealed class ToggleSwitch + public sealed class ToggleSwitch : IToggle { int onCount; @@ -12,7 +13,7 @@ public sealed class ToggleSwitch public static implicit operator bool(ToggleSwitch toggle) => toggle.Value; public Toggle On(bool conditional) => new Toggle(this, conditional ? 1 : 0); - public Toggle On() => new Toggle(this, 1); + public IDisposable On() => new Toggle(this, 1); public readonly struct Toggle : IDisposable { diff --git a/NebulaModel/IPlayerManager.cs b/NebulaModel/IPlayerManager.cs deleted file mode 100644 index f820bc186..000000000 --- a/NebulaModel/IPlayerManager.cs +++ /dev/null @@ -1,51 +0,0 @@ -using NebulaModel.DataStructures; -using NebulaModel.Networking; -using System.Collections.Generic; - -namespace NebulaModel -{ - public interface IPlayerManager - { - Locker GetPendingPlayers(out Dictionary pendingPlayers); - - Locker GetSyncingPlayers(out Dictionary syncingPlayers); - - Locker GetConnectedPlayers(out Dictionary connectedPlayers); - - Locker GetSavedPlayerData(out Dictionary savedPlayerData); - - PlayerData[] GetAllPlayerDataIncludingHost(); - - NebulaPlayer GetPlayer(NebulaConnection conn); - - NebulaPlayer GetSyncingPlayer(NebulaConnection conn); - - void SendPacketToAllPlayers(T packet) where T : class, new(); - - void SendPacketToLocalStar(T packet) where T : class, new(); - - void SendPacketToLocalPlanet(T packet) where T : class, new(); - - void SendPacketToPlanet(T packet, int planetId) where T : class, new(); - - void SendPacketToStar(T packet, int starId) where T : class, new(); - - void SendPacketToStarExcept(T packet, int starId, NebulaConnection exclude) where T : class, new(); - - void SendRawPacketToStar(byte[] rawPacket, int starId, NebulaConnection sender); - - void SendRawPacketToPlanet(byte[] rawPacket, int planetId, NebulaConnection sender); - - void SendPacketToOtherPlayers(T packet, NebulaPlayer sender) where T : class, new(); - - NebulaPlayer PlayerConnected(NebulaConnection conn); - - void PlayerDisconnected(NebulaConnection conn); - - ushort GetNextAvailablePlayerId(); - - void UpdateMechaData(MechaData mechaData, NebulaConnection conn); - - void SendTechRefundPackagesToClients(int techId); - } -} diff --git a/NebulaModel/MultiplayerOptions.cs b/NebulaModel/MultiplayerOptions.cs index 982438c32..28827ae54 100644 --- a/NebulaModel/MultiplayerOptions.cs +++ b/NebulaModel/MultiplayerOptions.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using System; using System.ComponentModel; diff --git a/NebulaModel/NebulaModel.csproj b/NebulaModel/NebulaModel.csproj index 4f0f72709..60069a787 100644 --- a/NebulaModel/NebulaModel.csproj +++ b/NebulaModel/NebulaModel.csproj @@ -2,6 +2,7 @@ + diff --git a/NebulaModel/NetworkProvider.cs b/NebulaModel/NetworkProvider.cs index f2b859ba7..6d3a913f3 100644 --- a/NebulaModel/NetworkProvider.cs +++ b/NebulaModel/NetworkProvider.cs @@ -1,14 +1,15 @@ -using NebulaModel.Networking; +using NebulaAPI; +using NebulaModel.Networking; using NebulaModel.Networking.Serialization; using System; namespace NebulaModel { - public abstract class NetworkProvider : IDisposable + public abstract class NetworkProvider : IDisposable, INetworkProvider { public NetPacketProcessor PacketProcessor { get; protected set; } - public readonly IPlayerManager PlayerManager; + public IPlayerManager PlayerManager { get; } protected NetworkProvider(IPlayerManager playerManager) { @@ -32,7 +33,7 @@ protected NetworkProvider(IPlayerManager playerManager) public abstract void SendPacketToStar(T packet, int starId) where T : class, new(); - public abstract void SendPacketToStarExclude(T packet, int starId, NebulaConnection exclude) + public abstract void SendPacketToStarExclude(T packet, int starId, INebulaConnection exclude) where T : class, new(); public abstract void Update(); diff --git a/NebulaModel/Networking/BinaryUtils.cs b/NebulaModel/Networking/BinaryUtils.cs index 354615ee4..6e830c821 100644 --- a/NebulaModel/Networking/BinaryUtils.cs +++ b/NebulaModel/Networking/BinaryUtils.cs @@ -1,4 +1,5 @@ using K4os.Compression.LZ4.Streams; +using NebulaAPI; using System; using System.IO; @@ -8,7 +9,7 @@ public static class BinaryUtils { const int BUFFER_SIZE = 8192; - public class Writer : IDisposable + public class Writer : IWriterProvider { readonly MemoryStream ms; readonly LZ4EncoderStream ls; @@ -41,7 +42,7 @@ public byte[] CloseAndGetBytes() } } - public class Reader : IDisposable + public class Reader : IReaderProvider { readonly MemoryStream ms; readonly LZ4DecoderStream ls; diff --git a/NebulaModel/Networking/DisconnectionReason.cs b/NebulaModel/Networking/DisconnectionReason.cs index 7eb3cf0ad..0f4398dfc 100644 --- a/NebulaModel/Networking/DisconnectionReason.cs +++ b/NebulaModel/Networking/DisconnectionReason.cs @@ -12,8 +12,10 @@ public enum DisconnectionReason ClientRequestedDisconnect = 2001, ModVersionMismatch = 2002, GameVersionMismatch = 2003, - + + // Mod Specific Error Codes - GalacticScaleMissmatch = 3000, + ModIsMissing = 2500, + ModIsMissingOnServer = 2501 } } diff --git a/NebulaModel/Networking/NebulaConnection.cs b/NebulaModel/Networking/NebulaConnection.cs index c211d9e29..9841d4b31 100644 --- a/NebulaModel/Networking/NebulaConnection.cs +++ b/NebulaModel/Networking/NebulaConnection.cs @@ -1,4 +1,5 @@ -using NebulaModel.Logger; +using NebulaAPI; +using NebulaModel.Logger; using NebulaModel.Networking.Serialization; using System; using System.Net; @@ -6,7 +7,7 @@ namespace NebulaModel.Networking { - public class NebulaConnection + public class NebulaConnection : INebulaConnection { private readonly EndPoint peerEndpoint; private readonly WebSocket peerSocket; diff --git a/NebulaModel/Networking/PacketUtils.cs b/NebulaModel/Networking/PacketUtils.cs index 468a10315..cfde8fc97 100644 --- a/NebulaModel/Networking/PacketUtils.cs +++ b/NebulaModel/Networking/PacketUtils.cs @@ -1,7 +1,6 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking.Serialization; -using NebulaModel.Packets; using NebulaModel.Utils; using System; using System.Linq; @@ -11,19 +10,18 @@ namespace NebulaModel.Networking { public static class PacketUtils { - public static void RegisterAllPacketNestedTypes(NetPacketProcessor packetProcessor) + + public static void RegisterAllPacketNestedTypesInAssembly(Assembly assembly, NetPacketProcessor packetProcessor) { - var nestedTypes = AssembliesUtils.GetTypesWithAttribute(); + var nestedTypes = AssembliesUtils.GetTypesWithAttributeInAssembly(assembly); foreach (Type type in nestedTypes) { Log.Info($"Registering Nested Type: {type.Name}"); if (type.IsClass) { - // TODO: Find a better way to get the "NetPacketProcessor.RegisterNestedType" that as the Func param instead of by index. - MethodInfo registerMethod = packetProcessor.GetType() - .GetMethods() + MethodInfo registerMethod = packetProcessor.GetType().GetMethods() .Where(m => m.Name == nameof(NetPacketProcessor.RegisterNestedType)) - .ToArray()[2] + .FirstOrDefault(m => m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType.Name.Equals(typeof(Func<>).Name)) .MakeGenericMethod(type); MethodInfo delegateMethod = packetProcessor.GetType().GetMethod(nameof(NetPacketProcessor.CreateNestedClassInstance)).MakeGenericMethod(type); @@ -44,9 +42,23 @@ public static void RegisterAllPacketNestedTypes(NetPacketProcessor packetProcess } } - public static void RegisterAllPacketProcessorsInCallingAssembly(NetPacketProcessor packetProcessor, bool isMasterClient) + private static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) { - var processors = Assembly.GetCallingAssembly().GetTypes() + while (toCheck != null && toCheck != typeof(object)) + { + var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; + if (generic == cur) + { + return true; + } + toCheck = toCheck.BaseType; + } + return false; + } + + public static void RegisterAllPacketProcessorsInAssembly(Assembly assembly, NetPacketProcessor packetProcessor, bool isMasterClient) + { + var processors = assembly.GetTypes() .Where(t => t.GetCustomAttributes(typeof(RegisterPacketProcessorAttribute), true).Length > 0); MethodInfo method = packetProcessor.GetType().GetMethods() @@ -56,29 +68,34 @@ public static void RegisterAllPacketProcessorsInCallingAssembly(NetPacketProcess foreach (Type type in processors) { - if (type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(PacketProcessor<>)) + if (IsSubclassOfRawGeneric(typeof(BasePacketProcessor<>), type)) { Type packetType = type.BaseType.GetGenericArguments().FirstOrDefault(); Log.Info($"Registering {type.Name} to process packet of type: {packetType.Name}"); // Create instance of the processor - Type delegateType = typeof(Action<,>).MakeGenericType(packetType, typeof(NebulaConnection)); + Type delegateType = typeof(Action<,>).MakeGenericType(packetType, typeof(INebulaConnection)); object processor = Activator.CreateInstance(type); - Delegate callback = Delegate.CreateDelegate(delegateType, processor, type.GetMethod(nameof(PacketProcessor.ProcessPacket))); + Delegate callback = Delegate.CreateDelegate(delegateType, processor, type.GetMethod(nameof(BasePacketProcessor.ProcessPacket), new Type[] { packetType, typeof(INebulaConnection) })); // Initialize processor type.BaseType.GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(processor, new object[] { isMasterClient }); // Register our processor callback to the PacketProcessor - Type subscribeGenericType = typeof(Action<,>).MakeGenericType(packetType, typeof(NebulaConnection)); - MethodInfo generic = method.MakeGenericMethod(packetType, typeof(NebulaConnection)); + Type subscribeGenericType = typeof(Action<,>).MakeGenericType(packetType, typeof(INebulaConnection)); + MethodInfo generic = method.MakeGenericMethod(packetType, typeof(INebulaConnection)); generic.Invoke(packetProcessor, new object[] { callback }); } else { - Log.Warn($"{type.FullName} registered, but doesn't implement {typeof(PacketProcessor<>).FullName}"); + Log.Warn($"{type.FullName} registered, but doesn't implement {typeof(BasePacketProcessor<>).FullName}"); } } } + + public static void RegisterAllPacketProcessorsInCallingAssembly(NetPacketProcessor packetProcessor, bool isMasterClient) + { + RegisterAllPacketProcessorsInAssembly(Assembly.GetCallingAssembly(), packetProcessor, isMasterClient); + } } } diff --git a/NebulaModel/Networking/Serialization/INetSerializable.cs b/NebulaModel/Networking/Serialization/INetSerializable.cs deleted file mode 100644 index c85fa2998..000000000 --- a/NebulaModel/Networking/Serialization/INetSerializable.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace NebulaModel.Networking.Serialization -{ - public interface INetSerializable - { - void Serialize(NetDataWriter writer); - void Deserialize(NetDataReader reader); - } -} diff --git a/NebulaModel/Networking/Serialization/NetDataReader.cs b/NebulaModel/Networking/Serialization/NetDataReader.cs index 0521e4bc8..11089e668 100644 --- a/NebulaModel/Networking/Serialization/NetDataReader.cs +++ b/NebulaModel/Networking/Serialization/NetDataReader.cs @@ -1,10 +1,11 @@ -using System; +using NebulaAPI; +using System; using System.Net; using System.Text; namespace NebulaModel.Networking.Serialization { - public class NetDataReader + public class NetDataReader : INetDataReader { protected byte[] _data; protected int _position; diff --git a/NebulaModel/Networking/Serialization/NetDataWriter.cs b/NebulaModel/Networking/Serialization/NetDataWriter.cs index cbada855d..7bc915882 100644 --- a/NebulaModel/Networking/Serialization/NetDataWriter.cs +++ b/NebulaModel/Networking/Serialization/NetDataWriter.cs @@ -1,10 +1,11 @@ -using System; +using NebulaAPI; +using System; using System.Net; using System.Text; namespace NebulaModel.Networking.Serialization { - public class NetDataWriter + public class NetDataWriter : INetDataWriter { protected byte[] _data; protected int _position; diff --git a/NebulaModel/Networking/Serialization/NetPacketProcessor.cs b/NebulaModel/Networking/Serialization/NetPacketProcessor.cs index 4d7f386ab..ac59bedad 100644 --- a/NebulaModel/Networking/Serialization/NetPacketProcessor.cs +++ b/NebulaModel/Networking/Serialization/NetPacketProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/NebulaModel/Networking/Serialization/NetSerializer.cs b/NebulaModel/Networking/Serialization/NetSerializer.cs index 3940e3d19..8490a7cef 100644 --- a/NebulaModel/Networking/Serialization/NetSerializer.cs +++ b/NebulaModel/Networking/Serialization/NetSerializer.cs @@ -1,4 +1,5 @@ -using System; +using NebulaAPI; +using System; using System.Collections.Generic; using System.Net; using System.Reflection; diff --git a/NebulaModel/Packets/Belt/BeltUpdatePickupItemsPacket.cs b/NebulaModel/Packets/Belt/BeltUpdatePickupItemsPacket.cs index 616171005..8705dc1d3 100644 --- a/NebulaModel/Packets/Belt/BeltUpdatePickupItemsPacket.cs +++ b/NebulaModel/Packets/Belt/BeltUpdatePickupItemsPacket.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking.Serialization; namespace NebulaModel.Packets.Belt @@ -32,7 +32,7 @@ public BeltUpdate(int itemId, int count, int beltId, int segId) BeltId = beltId; } - public void Serialize(NetDataWriter writer) + public void Serialize(INetDataWriter writer) { writer.Put(ItemId); writer.Put(Count); @@ -40,7 +40,7 @@ public void Serialize(NetDataWriter writer) writer.Put(SegId); } - public void Deserialize(NetDataReader reader) + public void Deserialize(INetDataReader reader) { ItemId = reader.GetInt(); Count = reader.GetInt(); diff --git a/NebulaModel/Packets/Factory/FoundationBuildUpdatePacket.cs b/NebulaModel/Packets/Factory/FoundationBuildUpdatePacket.cs index 3f66c318a..2cc1e086a 100644 --- a/NebulaModel/Packets/Factory/FoundationBuildUpdatePacket.cs +++ b/NebulaModel/Packets/Factory/FoundationBuildUpdatePacket.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using UnityEngine; namespace NebulaModel.Packets.Factory diff --git a/NebulaModel/Packets/Factory/Inserter/NewSetInserterInsertTargetPacket.cs b/NebulaModel/Packets/Factory/Inserter/NewSetInserterInsertTargetPacket.cs index 8afd583ab..dbc2bd6b9 100644 --- a/NebulaModel/Packets/Factory/Inserter/NewSetInserterInsertTargetPacket.cs +++ b/NebulaModel/Packets/Factory/Inserter/NewSetInserterInsertTargetPacket.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using UnityEngine; namespace NebulaModel.Packets.Factory.Inserter diff --git a/NebulaModel/Packets/Factory/Inserter/NewSetInserterPickTargetPacket.cs b/NebulaModel/Packets/Factory/Inserter/NewSetInserterPickTargetPacket.cs index f146cfef6..26dd6b100 100644 --- a/NebulaModel/Packets/Factory/Inserter/NewSetInserterPickTargetPacket.cs +++ b/NebulaModel/Packets/Factory/Inserter/NewSetInserterPickTargetPacket.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using UnityEngine; namespace NebulaModel.Packets.Factory.Inserter diff --git a/NebulaModel/Packets/GameStates/GameStateUpdate.cs b/NebulaModel/Packets/GameStates/GameStateUpdate.cs index 614dfc67b..1c4278549 100644 --- a/NebulaModel/Packets/GameStates/GameStateUpdate.cs +++ b/NebulaModel/Packets/GameStates/GameStateUpdate.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.DataStructures; namespace NebulaModel.Packets.GameStates diff --git a/NebulaModel/Packets/Logistics/ILSShipDock.cs b/NebulaModel/Packets/Logistics/ILSShipDock.cs index 17f0c77e4..a261dbe55 100644 --- a/NebulaModel/Packets/Logistics/ILSShipDock.cs +++ b/NebulaModel/Packets/Logistics/ILSShipDock.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using UnityEngine; namespace NebulaModel.Packets.Logistics diff --git a/NebulaModel/Packets/Logistics/ILSgStationPoolSync.cs b/NebulaModel/Packets/Logistics/ILSgStationPoolSync.cs index a4ade2b4c..9bd168272 100644 --- a/NebulaModel/Packets/Logistics/ILSgStationPoolSync.cs +++ b/NebulaModel/Packets/Logistics/ILSgStationPoolSync.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; namespace NebulaModel.Packets.Logistics { diff --git a/NebulaModel/Packets/PacketProcessor.cs b/NebulaModel/Packets/PacketProcessor.cs index e1074326a..8ff76d201 100644 --- a/NebulaModel/Packets/PacketProcessor.cs +++ b/NebulaModel/Packets/PacketProcessor.cs @@ -1,15 +1,13 @@ -using NebulaModel.Networking; +using NebulaAPI; +using NebulaModel.Networking; namespace NebulaModel.Packets { - public abstract class PacketProcessor + public abstract class PacketProcessor : BasePacketProcessor { - protected bool IsHost; - protected bool IsClient => !IsHost; - - internal void Initialize(bool isHost) + public override void ProcessPacket(T packet, INebulaConnection conn) { - IsHost = isHost; + this.ProcessPacket(packet, (NebulaConnection)conn); } public abstract void ProcessPacket(T packet, NebulaConnection conn); diff --git a/NebulaModel/Packets/Players/NewDroneOrderPacket.cs b/NebulaModel/Packets/Players/NewDroneOrderPacket.cs index d841f2d9b..52d146a4c 100644 --- a/NebulaModel/Packets/Players/NewDroneOrderPacket.cs +++ b/NebulaModel/Packets/Players/NewDroneOrderPacket.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using UnityEngine; namespace NebulaModel.Packets.Players diff --git a/NebulaModel/Packets/Players/PlayerAnimationUpdate.cs b/NebulaModel/Packets/Players/PlayerAnimationUpdate.cs index c92609724..ca34c1edb 100644 --- a/NebulaModel/Packets/Players/PlayerAnimationUpdate.cs +++ b/NebulaModel/Packets/Players/PlayerAnimationUpdate.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.DataStructures; namespace NebulaModel.Packets.Players diff --git a/NebulaModel/Packets/Players/PlayerColorChanged.cs b/NebulaModel/Packets/Players/PlayerColorChanged.cs index 57f3ab24a..8fd04f9e9 100644 --- a/NebulaModel/Packets/Players/PlayerColorChanged.cs +++ b/NebulaModel/Packets/Players/PlayerColorChanged.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; namespace NebulaModel.Packets.Players { diff --git a/NebulaModel/Packets/Players/PlayerMechaData.cs b/NebulaModel/Packets/Players/PlayerMechaData.cs index 5458c03fe..80b0241f2 100644 --- a/NebulaModel/Packets/Players/PlayerMechaData.cs +++ b/NebulaModel/Packets/Players/PlayerMechaData.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.DataStructures; namespace NebulaModel.Packets.Players diff --git a/NebulaModel/Packets/Players/PlayerMovement.cs b/NebulaModel/Packets/Players/PlayerMovement.cs index b191cbd29..67ad24f07 100644 --- a/NebulaModel/Packets/Players/PlayerMovement.cs +++ b/NebulaModel/Packets/Players/PlayerMovement.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.DataStructures; namespace NebulaModel.Packets.Players diff --git a/NebulaModel/Packets/Players/PlayerTechBonuses.cs b/NebulaModel/Packets/Players/PlayerTechBonuses.cs index 1a165f073..bbc190535 100644 --- a/NebulaModel/Packets/Players/PlayerTechBonuses.cs +++ b/NebulaModel/Packets/Players/PlayerTechBonuses.cs @@ -1,35 +1,36 @@ -using NebulaModel.Networking.Serialization; +using NebulaAPI; +using NebulaModel.Networking.Serialization; namespace NebulaModel.Packets.Players { - public class PlayerTechBonuses : INetSerializable + public class PlayerTechBonuses : IPlayerTechBonuses { - double coreEnergyCap { get; set; } - double corePowerGen { get; set; } - double reactorPowerGen { get; set; } - double walkPower { get; set; } - double jumpEnergy { get; set; } - double thrustPowerPerAcc { get; set; } - double warpKeepingPowerPerSpeed { get; set; } - double warpStartPowerPerSpeed { get; set; } - double miningPower { get; set; } - double replicatePower { get; set; } - double researchPower { get; set; } - double droneEjectEnergy { get; set; } - double droneEnergyPerMeter { get; set; } - int coreLevel { get; set; } - int thrusterLevel { get; set; } - float miningSpeed { get; set; } - float replicateSpeed { get; set; } - float walkSpeed { get; set; } - float jumpSpeed { get; set; } - float maxSailSpeed { get; set; } - float maxWarpSpeed { get; set; } - float buildArea { get; set; } - int droneCount { get; set; } - float droneSpeed { get; set; } - int droneMovement { get; set; } - int inventorySize { get; set; } + public double coreEnergyCap { get; set; } + public double corePowerGen { get; set; } + public double reactorPowerGen { get; set; } + public double walkPower { get; set; } + public double jumpEnergy { get; set; } + public double thrustPowerPerAcc { get; set; } + public double warpKeepingPowerPerSpeed { get; set; } + public double warpStartPowerPerSpeed { get; set; } + public double miningPower { get; set; } + public double replicatePower { get; set; } + public double researchPower { get; set; } + public double droneEjectEnergy { get; set; } + public double droneEnergyPerMeter { get; set; } + public int coreLevel { get; set; } + public int thrusterLevel { get; set; } + public float miningSpeed { get; set; } + public float replicateSpeed { get; set; } + public float walkSpeed { get; set; } + public float jumpSpeed { get; set; } + public float maxSailSpeed { get; set; } + public float maxWarpSpeed { get; set; } + public float buildArea { get; set; } + public int droneCount { get; set; } + public float droneSpeed { get; set; } + public int droneMovement { get; set; } + public int inventorySize { get; set; } public PlayerTechBonuses() { } @@ -96,7 +97,7 @@ public void UpdateMech(Mecha destination) } } - public void Serialize(NetDataWriter writer) + public void Serialize(INetDataWriter writer) { writer.Put(coreEnergyCap); writer.Put(corePowerGen); @@ -126,7 +127,7 @@ public void Serialize(NetDataWriter writer) writer.Put(inventorySize); } - public void Deserialize(NetDataReader reader) + public void Deserialize(INetDataReader reader) { coreEnergyCap = reader.GetDouble(); corePowerGen = reader.GetDouble(); diff --git a/NebulaModel/Packets/Session/HandshakeRequest.cs b/NebulaModel/Packets/Session/HandshakeRequest.cs index 2302cd478..139457a46 100644 --- a/NebulaModel/Packets/Session/HandshakeRequest.cs +++ b/NebulaModel/Packets/Session/HandshakeRequest.cs @@ -1,4 +1,6 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; +using NebulaModel.Networking; namespace NebulaModel.Packets.Session { @@ -6,7 +8,8 @@ public class HandshakeRequest { public string Username { get; set; } public Float3 MechaColor { get; set; } - public string ModVersion { get; set; } + public byte[] ModsVersion { get; set; } + public int ModsCount { get; set; } public int GameVersionSig { get; set; } public byte[] ClientCert { get; set; } @@ -14,11 +17,28 @@ public HandshakeRequest() { } public HandshakeRequest(byte[] clientCert, string username, Float3 mechaColor) { - this.Username = username; - this.MechaColor = mechaColor; - this.ModVersion = Config.ModVersion; - this.GameVersionSig = GameConfig.gameVersion.sig; - this.ClientCert = clientCert; + Username = username; + MechaColor = mechaColor; + + using (BinaryUtils.Writer writer = new BinaryUtils.Writer()) + { + int count = 0; + foreach (var pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) + { + if (pluginInfo.Value.Instance is IMultiplayerMod mod) + { + writer.BinaryWriter.Write(pluginInfo.Key); + writer.BinaryWriter.Write(mod.Version); + count++; + } + } + + ModsVersion = writer.CloseAndGetBytes(); + ModsCount = count; + } + + GameVersionSig = GameConfig.gameVersion.sig; + ClientCert = clientCert; } } } diff --git a/NebulaModel/Packets/Session/HandshakeResponse.cs b/NebulaModel/Packets/Session/HandshakeResponse.cs index d4cef21a7..1a40d7f3f 100644 --- a/NebulaModel/Packets/Session/HandshakeResponse.cs +++ b/NebulaModel/Packets/Session/HandshakeResponse.cs @@ -10,10 +10,12 @@ public class HandshakeResponse public float ResourceMultiplier { get; set; } public bool IsNewPlayer { get; set; } public PlayerData LocalPlayerData { get; set; } - + public byte[] ModsSettings { get; set; } + public int ModsSettingsCount { get; set; } + public HandshakeResponse() { } - public HandshakeResponse(int algoVersion, int galaxySeed, int starCount, float resourceMultiplier, bool isNewPlayer, PlayerData localPlayerData) + public HandshakeResponse(int algoVersion, int galaxySeed, int starCount, float resourceMultiplier, bool isNewPlayer, PlayerData localPlayerData, byte[] modsSettings, int settingsCount) { AlgoVersion = algoVersion; GalaxySeed = galaxySeed; @@ -21,6 +23,8 @@ public HandshakeResponse(int algoVersion, int galaxySeed, int starCount, float r ResourceMultiplier = resourceMultiplier; IsNewPlayer = isNewPlayer; LocalPlayerData = localPlayerData; + ModsSettings = modsSettings; + ModsSettingsCount = settingsCount; } } } diff --git a/NebulaModel/Packets/Session/PingPacket.cs b/NebulaModel/Packets/Session/PingPacket.cs index fd379699e..06b1391bb 100644 --- a/NebulaModel/Packets/Session/PingPacket.cs +++ b/NebulaModel/Packets/Session/PingPacket.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using System; namespace NebulaModel.Packets.Session diff --git a/NebulaModel/Packets/Session/SyncComplete.cs b/NebulaModel/Packets/Session/SyncComplete.cs index 75dd19f28..48e103331 100644 --- a/NebulaModel/Packets/Session/SyncComplete.cs +++ b/NebulaModel/Packets/Session/SyncComplete.cs @@ -1,4 +1,6 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; +using System.Linq; namespace NebulaModel.Packets.Session { @@ -7,9 +9,9 @@ public class SyncComplete public PlayerData[] AllPlayers { get; set; } public SyncComplete() { AllPlayers = new PlayerData[] { }; } - public SyncComplete(PlayerData[] otherPlayers) + public SyncComplete(IPlayerData[] otherPlayers) { - AllPlayers = otherPlayers; + AllPlayers = otherPlayers.Select(data => (PlayerData)data).ToArray(); } } } diff --git a/NebulaModel/Packets/Trash/TrashSystemNewTrashCreatedPacket.cs b/NebulaModel/Packets/Trash/TrashSystemNewTrashCreatedPacket.cs index 89425fb99..a145d009f 100644 --- a/NebulaModel/Packets/Trash/TrashSystemNewTrashCreatedPacket.cs +++ b/NebulaModel/Packets/Trash/TrashSystemNewTrashCreatedPacket.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; namespace NebulaModel.Packets.Trash { diff --git a/NebulaModel/Packets/Universe/DysonSphereAddLayerPacket.cs b/NebulaModel/Packets/Universe/DysonSphereAddLayerPacket.cs index 4ecc415f8..d807731a6 100644 --- a/NebulaModel/Packets/Universe/DysonSphereAddLayerPacket.cs +++ b/NebulaModel/Packets/Universe/DysonSphereAddLayerPacket.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using UnityEngine; namespace NebulaModel.Packets.Universe diff --git a/NebulaModel/Packets/Universe/DysonSphereAddNodePacket.cs b/NebulaModel/Packets/Universe/DysonSphereAddNodePacket.cs index 5b43b0212..1ae911e03 100644 --- a/NebulaModel/Packets/Universe/DysonSphereAddNodePacket.cs +++ b/NebulaModel/Packets/Universe/DysonSphereAddNodePacket.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; namespace NebulaModel.Packets.Universe { diff --git a/NebulaModel/Packets/Universe/DysonSphereBulletCorrectionPacket.cs b/NebulaModel/Packets/Universe/DysonSphereBulletCorrectionPacket.cs index da62c756c..47e4a1dee 100644 --- a/NebulaModel/Packets/Universe/DysonSphereBulletCorrectionPacket.cs +++ b/NebulaModel/Packets/Universe/DysonSphereBulletCorrectionPacket.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using UnityEngine; namespace NebulaModel.Packets.Universe diff --git a/NebulaModel/Packets/Universe/DysonSwarmAddOrbitPacket.cs b/NebulaModel/Packets/Universe/DysonSwarmAddOrbitPacket.cs index 2d8987619..cb0b78424 100644 --- a/NebulaModel/Packets/Universe/DysonSwarmAddOrbitPacket.cs +++ b/NebulaModel/Packets/Universe/DysonSwarmAddOrbitPacket.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using UnityEngine; namespace NebulaModel.Packets.Universe diff --git a/NebulaModel/Player.cs b/NebulaModel/Player.cs index 4bbab295f..ade1bf306 100644 --- a/NebulaModel/Player.cs +++ b/NebulaModel/Player.cs @@ -1,12 +1,13 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using NebulaModel.Networking; namespace NebulaModel { - public class NebulaPlayer + public class NebulaPlayer : INebulaPlayer { - public NebulaConnection Connection { get; private set; } - public PlayerData Data { get; private set; } + public INebulaConnection Connection { get; private set; } + public IPlayerData Data { get; private set; } public ushort Id => Data.PlayerId; public int CurrentResearchId { get; private set; } public long TechProgressContributed { get; private set; } @@ -24,10 +25,10 @@ public NebulaPlayer(NebulaConnection connection, PlayerData data) public void SendRawPacket(byte[] packet) { - Connection.SendRawPacket(packet); + ((NebulaConnection)Connection).SendRawPacket(packet); } - public void LoadUserData(PlayerData data) + public void LoadUserData(IPlayerData data) { ushort localId = Id; Data = data; diff --git a/NebulaModel/Utils/AssembliesUtils.cs b/NebulaModel/Utils/AssembliesUtils.cs index 2aba8dfd6..a1d7c8942 100644 --- a/NebulaModel/Utils/AssembliesUtils.cs +++ b/NebulaModel/Utils/AssembliesUtils.cs @@ -7,17 +7,19 @@ namespace NebulaModel.Utils { public static class AssembliesUtils { - public static IEnumerable GetTypesWithAttribute() where T : Attribute + public static IEnumerable GetTypesWithAttributeInAssembly(Assembly assembly) where T : Attribute { - return AppDomain.CurrentDomain.GetAssemblies() - .Where(a => a.FullName.StartsWith("Nebula")) - .SelectMany(a => a.GetTypes()) - .Where(t => t.GetCustomAttributes(typeof(T), true).Length > 0); + return assembly.GetTypes().Where(t => t.GetCustomAttributes(typeof(T), true).Length > 0); + } + + public static IEnumerable GetNebulaAssemblies() + { + return AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("Nebula")); } public static Assembly GetAssemblyByName(string name) { - return AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith($"{name}.")).FirstOrDefault(); + return AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName.StartsWith($"{name}.")); } } } diff --git a/NebulaNetwork/Client.cs b/NebulaNetwork/Client.cs index 2d569ab54..1970147a9 100644 --- a/NebulaNetwork/Client.cs +++ b/NebulaNetwork/Client.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel; using NebulaModel.DataStructures; using NebulaModel.Logger; @@ -10,6 +11,7 @@ using NebulaWorld; using System.Net; using System.Net.Sockets; +using System.Reflection; using UnityEngine; using WebSocketSharp; @@ -39,8 +41,17 @@ public Client(IPEndPoint endpoint) : base(null) public override void Start() { - PacketUtils.RegisterAllPacketNestedTypes(PacketProcessor); + foreach (Assembly assembly in AssembliesUtils.GetNebulaAssemblies()) + { + PacketUtils.RegisterAllPacketNestedTypesInAssembly(assembly, PacketProcessor); + } PacketUtils.RegisterAllPacketProcessorsInCallingAssembly(PacketProcessor, false); + + foreach (Assembly assembly in NebulaModAPI.TargetAssemblies) + { + PacketUtils.RegisterAllPacketNestedTypesInAssembly(assembly, PacketProcessor); + PacketUtils.RegisterAllPacketProcessorsInAssembly(assembly, PacketProcessor, false); + } #if DEBUG PacketProcessor.SimulateLatency = true; #endif @@ -52,7 +63,7 @@ public override void Start() clientSocket.Connect(); - Multiplayer.Session.LocalPlayer.IsHost = false; + ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false; if (Config.Options.RememberLastIP) { @@ -60,11 +71,15 @@ public override void Start() Config.Options.LastIP = serverEndpoint.ToString(); Config.SaveOptions(); } + + NebulaModAPI.OnMultiplayerGameStarted?.Invoke(); } public override void Stop() { clientSocket?.Close((ushort)DisconnectionReason.ClientRequestedDisconnect, "Player left the game"); + + NebulaModAPI.OnMultiplayerGameEnded?.Invoke(); } public override void Dispose() @@ -99,7 +114,7 @@ public override void SendPacketToStar(T packet, int starId) throw new System.NotImplementedException(); } - public override void SendPacketToStarExclude(T packet, int starId, NebulaConnection exclude) + public override void SendPacketToStarExclude(T packet, int starId, INebulaConnection exclude) { // Only possible from host throw new System.NotImplementedException(); diff --git a/NebulaNetwork/NebulaNetwork.csproj b/NebulaNetwork/NebulaNetwork.csproj index 6bcec1e15..d03e1aea5 100644 --- a/NebulaNetwork/NebulaNetwork.csproj +++ b/NebulaNetwork/NebulaNetwork.csproj @@ -2,6 +2,7 @@ + diff --git a/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerRecipeEventProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerRecipeEventProcessor.cs index 955b5b2b2..3b21eaee9 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerRecipeEventProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerRecipeEventProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Assembler; diff --git a/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerUpdateProducesProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerUpdateProducesProcessor.cs index d283be930..548b55a79 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerUpdateProducesProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerUpdateProducesProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Assembler; diff --git a/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerUpdateStorageProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerUpdateStorageProcessor.cs index d6cf619cb..da5e77a84 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerUpdateStorageProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Assembler/AssemblerUpdateStorageProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Assembler; diff --git a/NebulaNetwork/PacketProcessors/Factory/Belt/BeltUpdatePickupItemsProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Belt/BeltUpdatePickupItemsProcessor.cs index 137758d19..7fd28fcce 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Belt/BeltUpdatePickupItemsProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Belt/BeltUpdatePickupItemsProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Belt; diff --git a/NebulaNetwork/PacketProcessors/Factory/Belt/BeltUpdatePutItemOnProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Belt/BeltUpdatePutItemOnProcessor.cs index 9e089c27a..5615bcc85 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Belt/BeltUpdatePutItemOnProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Belt/BeltUpdatePutItemOnProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Belt; diff --git a/NebulaNetwork/PacketProcessors/Factory/Ejector/EjectorOrbitUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Ejector/EjectorOrbitUpdateProcessor.cs index 3ae037003..584893ec4 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Ejector/EjectorOrbitUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Ejector/EjectorOrbitUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Ejector; diff --git a/NebulaNetwork/PacketProcessors/Factory/Ejector/EjectorStorageUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Ejector/EjectorStorageUpdateProcessor.cs index c34d23b50..3b27069b3 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Ejector/EjectorStorageUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Ejector/EjectorStorageUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Ejector; diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/BuildEntityRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/BuildEntityRequestProcessor.cs index b638c1967..fd0cd96fb 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/BuildEntityRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/BuildEntityRequestProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; @@ -43,8 +43,8 @@ public override void ProcessPacket(BuildEntityRequest packet, NebulaConnection c } Multiplayer.Session.Factories.EventFactory = null; - Multiplayer.Session.Factories.PacketAuthor = FactoryManager.AUTHOR_NONE; - Multiplayer.Session.Factories.TargetPlanet = FactoryManager.PLANET_NONE; + Multiplayer.Session.Factories.PacketAuthor = NebulaModAPI.AUTHOR_NONE; + Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE; } } } diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/CreatePrebuildsRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/CreatePrebuildsRequestProcessor.cs index 1b66565fc..6aa02e07c 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/CreatePrebuildsRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/CreatePrebuildsRequestProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/DestructEntityRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/DestructEntityRequestProcessor.cs index bb5e27711..a5ff92b9d 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/DestructEntityRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/DestructEntityRequestProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory; @@ -35,8 +36,8 @@ public override void ProcessPacket(DestructEntityRequest packet, NebulaConnectio pab.factory = tmpFactory; pab.noneTool.factory = tmpFactory; - Multiplayer.Session.Factories.TargetPlanet = FactoryManager.PLANET_NONE; - Multiplayer.Session.Factories.PacketAuthor = FactoryManager.AUTHOR_NONE; + Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE; + Multiplayer.Session.Factories.PacketAuthor = NebulaModAPI.AUTHOR_NONE; } } } diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/PasteBuildingSettingUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/PasteBuildingSettingUpdateProcessor.cs index df271aefb..2e2e8316d 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/PasteBuildingSettingUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/PasteBuildingSettingUpdateProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs index c9fe3d575..94a7acd3a 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Entity/UpgradeEntityRequestProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory; @@ -30,8 +30,8 @@ public override void ProcessPacket(UpgradeEntityRequest packet, NebulaConnection ItemProto itemProto = LDB.items.Select(packet.UpgradeProtoId); planet.factory.UpgradeFinally(GameMain.mainPlayer, packet.ObjId, itemProto); - Multiplayer.Session.Factories.TargetPlanet = FactoryManager.PLANET_NONE; - Multiplayer.Session.Factories.PacketAuthor = FactoryManager.AUTHOR_NONE; + Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE; + Multiplayer.Session.Factories.PacketAuthor = NebulaModAPI.AUTHOR_NONE; } } } diff --git a/NebulaNetwork/PacketProcessors/Factory/Foundation/FoundationBuildUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Foundation/FoundationBuildUpdateProcessor.cs index c49670956..54b7d6d2c 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Foundation/FoundationBuildUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Foundation/FoundationBuildUpdateProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using NebulaModel.DataStructures; using NebulaModel.Networking; using NebulaModel.Packets; @@ -33,7 +34,7 @@ public override void ProcessPacket(FoundationBuildUpdatePacket packet, NebulaCon Multiplayer.Session.Factories.TargetPlanet = packet.PlanetId; Multiplayer.Session.Factories.AddPlanetTimer(packet.PlanetId); - Multiplayer.Session.Factories.TargetPlanet = FactoryManager.PLANET_NONE; + Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE; //Perform terrain operation int reformPointsCount = factory.planet.aux.ReformSnap(packet.GroundTestPos.ToVector3(), packet.ReformSize, packet.ReformType, packet.ReformColor, reformPoints, packet.ReformIndices, factory.platformSystem, out Vector3 reformCenterPoint); diff --git a/NebulaNetwork/PacketProcessors/Factory/Inserter/InserterFilterUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Inserter/InserterFilterUpdateProcessor.cs index 71a6955c5..d4417bcbd 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Inserter/InserterFilterUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Inserter/InserterFilterUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Inserter; diff --git a/NebulaNetwork/PacketProcessors/Factory/Inserter/NewSetInserterInsertTargetProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Inserter/NewSetInserterInsertTargetProcessor.cs index 4e9361c61..a74bd6889 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Inserter/NewSetInserterInsertTargetProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Inserter/NewSetInserterInsertTargetProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using NebulaModel.DataStructures; using NebulaModel.Networking; using NebulaModel.Packets; @@ -20,7 +21,7 @@ public override void ProcessPacket(NewSetInserterInsertTargetPacket packet, Nebu factory.WriteObjectConn(packet.ObjId, 1, false, packet.OtherObjId, -1); factory.factorySystem.SetInserterInsertTarget(packet.InserterId, packet.OtherObjId, packet.Offset); factory.factorySystem.inserterPool[packet.InserterId].pos2 = packet.PointPos.ToVector3(); - Multiplayer.Session.Factories.TargetPlanet = FactoryManager.PLANET_NONE; + Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE; } } } diff --git a/NebulaNetwork/PacketProcessors/Factory/Inserter/NewSetInserterPickTargetProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Inserter/NewSetInserterPickTargetProcessor.cs index cf377862a..bcfdc4953 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Inserter/NewSetInserterPickTargetProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Inserter/NewSetInserterPickTargetProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using NebulaModel.DataStructures; using NebulaModel.Networking; using NebulaModel.Packets; @@ -20,7 +21,7 @@ public override void ProcessPacket(NewSetInserterPickTargetPacket packet, Nebula factory.WriteObjectConn(packet.ObjId, 1, false, packet.OtherObjId, -1); factory.factorySystem.SetInserterPickTarget(packet.InserterId, packet.OtherObjId, packet.Offset); factory.entityPool[packet.ObjId].pos = packet.PointPos.ToVector3(); - Multiplayer.Session.Factories.TargetPlanet = FactoryManager.PLANET_NONE; + Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE; } } } diff --git a/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateCubesProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateCubesProcessor.cs index d03561ad2..40e7a23b0 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateCubesProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateCubesProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Laboratory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateEventProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateEventProcessor.cs index 758be585f..4f97c0227 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateEventProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateEventProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Laboratory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateStorageProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateStorageProcessor.cs index eab91fecb..7eb1aae23 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateStorageProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Laboratory/LaboratoryUpdateStorageProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Laboratory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Miner/MinerStoragePickupProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Miner/MinerStoragePickupProcessor.cs index 75343d020..2ccc3bd4e 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Miner/MinerStoragePickupProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Miner/MinerStoragePickupProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Miner; diff --git a/NebulaNetwork/PacketProcessors/Factory/PowerExchanger/PowerExchangerChangeModeProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/PowerExchanger/PowerExchangerChangeModeProcessor.cs index 8744fe9e3..6b1f4fe82 100644 --- a/NebulaNetwork/PacketProcessors/Factory/PowerExchanger/PowerExchangerChangeModeProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/PowerExchanger/PowerExchangerChangeModeProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.PowerExchanger; diff --git a/NebulaNetwork/PacketProcessors/Factory/PowerExchanger/PowerExchangerStorageUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/PowerExchanger/PowerExchangerStorageUpdateProcessor.cs index 480dee623..282da2b85 100644 --- a/NebulaNetwork/PacketProcessors/Factory/PowerExchanger/PowerExchangerStorageUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/PowerExchanger/PowerExchangerStorageUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.PowerExchanger; diff --git a/NebulaNetwork/PacketProcessors/Factory/PowerGenerator/PowerGeneratorFuelUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/PowerGenerator/PowerGeneratorFuelUpdateProcessor.cs index 2c2d40d73..6a5b8a66c 100644 --- a/NebulaNetwork/PacketProcessors/Factory/PowerGenerator/PowerGeneratorFuelUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/PowerGenerator/PowerGeneratorFuelUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.PowerGenerator; diff --git a/NebulaNetwork/PacketProcessors/Factory/PowerTower/PowerTowerUserLoadRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/PowerTower/PowerTowerUserLoadRequestProcessor.cs index 15340fdca..7dc50d9f6 100644 --- a/NebulaNetwork/PacketProcessors/Factory/PowerTower/PowerTowerUserLoadRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/PowerTower/PowerTowerUserLoadRequestProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.PowerTower; diff --git a/NebulaNetwork/PacketProcessors/Factory/PowerTower/PowerTowerUserLoadResponseProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/PowerTower/PowerTowerUserLoadResponseProcessor.cs index ccf046568..252bd5d4d 100644 --- a/NebulaNetwork/PacketProcessors/Factory/PowerTower/PowerTowerUserLoadResponseProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/PowerTower/PowerTowerUserLoadResponseProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.PowerTower; diff --git a/NebulaNetwork/PacketProcessors/Factory/RayReceiver/RayReceiverChangeLensProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/RayReceiver/RayReceiverChangeLensProcessor.cs index c37386da8..e9aaf42cc 100644 --- a/NebulaNetwork/PacketProcessors/Factory/RayReceiver/RayReceiverChangeLensProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/RayReceiver/RayReceiverChangeLensProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.RayReceiver; diff --git a/NebulaNetwork/PacketProcessors/Factory/RayReceiver/RayReceiverChangeModeProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/RayReceiver/RayReceiverChangeModeProcessor.cs index 40c6397b5..0fc7cb693 100644 --- a/NebulaNetwork/PacketProcessors/Factory/RayReceiver/RayReceiverChangeModeProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/RayReceiver/RayReceiverChangeModeProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.RayReceiver; diff --git a/NebulaNetwork/PacketProcessors/Factory/Silo/SiloStorageUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Silo/SiloStorageUpdateProcessor.cs index df4705557..276915168 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Silo/SiloStorageUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Silo/SiloStorageUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Silo; diff --git a/NebulaNetwork/PacketProcessors/Factory/Splitter/SplitterFilterChangeProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Splitter/SplitterFilterChangeProcessor.cs index f32546b18..0cc4273f5 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Splitter/SplitterFilterChangeProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Splitter/SplitterFilterChangeProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Splitter; diff --git a/NebulaNetwork/PacketProcessors/Factory/Splitter/SplitterPriorityChangeProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Splitter/SplitterPriorityChangeProcessor.cs index 5d827bf8f..534ff3483 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Splitter/SplitterPriorityChangeProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Splitter/SplitterPriorityChangeProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Splitter; diff --git a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRealtimeChangeProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRealtimeChangeProcessor.cs index 8e8d92539..717186f35 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRealtimeChangeProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRealtimeChangeProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRequestProcessor.cs index 3162b294c..fa1e026a4 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncRequestProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncResponseProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncResponseProcessor.cs index dac1b33c9..241a0dfbd 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncResponseProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncResponseProcessor.cs @@ -1,5 +1,4 @@ -using HarmonyLib; -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncSetBansProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncSetBansProcessor.cs index f04fd413b..39c902a67 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncSetBansProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncSetBansProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncSortProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncSortProcessor.cs index 788b2bec7..42052ebb5 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncSortProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncSortProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory; diff --git a/NebulaNetwork/PacketProcessors/Factory/Tank/TankInputOutputSwitchProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Tank/TankInputOutputSwitchProcessor.cs index 51f5f45ed..0ffdfd125 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Tank/TankInputOutputSwitchProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Tank/TankInputOutputSwitchProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Tank; diff --git a/NebulaNetwork/PacketProcessors/Factory/Tank/TankStorageUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Factory/Tank/TankStorageUpdateProcessor.cs index 574be01a3..82c877700 100644 --- a/NebulaNetwork/PacketProcessors/Factory/Tank/TankStorageUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Factory/Tank/TankStorageUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Factory.Tank; diff --git a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryDataRequestProcessor.cs b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryDataRequestProcessor.cs index 1c190e229..6e85be787 100644 --- a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryDataRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryDataRequestProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.GameHistory; diff --git a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryDataResponseProcessor.cs b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryDataResponseProcessor.cs index 64d730509..b190bb15f 100644 --- a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryDataResponseProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryDataResponseProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryEnqueueTechProcessor.cs b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryEnqueueTechProcessor.cs index f79dfd33a..31458a193 100644 --- a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryEnqueueTechProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryEnqueueTechProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -21,7 +22,7 @@ public override void ProcessPacket(GameHistoryEnqueueTechPacket packet, NebulaCo { if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { using (Multiplayer.Session.History.IsIncomingRequest.On()) diff --git a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryNotificationProcessor.cs b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryNotificationProcessor.cs index f2715dc6d..5a1708936 100644 --- a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryNotificationProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryNotificationProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -24,7 +25,7 @@ public override void ProcessPacket(GameHistoryNotificationPacket packet, NebulaC if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else diff --git a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryRemoveTechProcessor.cs b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryRemoveTechProcessor.cs index 4f81d3b72..d5f344dd0 100644 --- a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryRemoveTechProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryRemoveTechProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Logger; using NebulaModel.Networking; @@ -24,7 +25,7 @@ public override void ProcessPacket(GameHistoryRemoveTechPacket packet, NebulaCon bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else diff --git a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryResearchContributionProcessor.cs b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryResearchContributionProcessor.cs index bd4b97ed8..9f5b80a3b 100644 --- a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryResearchContributionProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryResearchContributionProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Logger; using NebulaModel.Networking; @@ -21,7 +22,7 @@ public override void ProcessPacket(GameHistoryResearchContributionPacket packet, Log.Info($"ProcessPacket researchContribution: got package for same tech"); GameMain.history.AddTechHash(packet.Hashes); IPlayerManager playerManager = Multiplayer.Session.Network.PlayerManager; - playerManager.GetPlayer(conn).UpdateResearchProgress(packet.TechId, packet.Hashes); + ((NebulaPlayer)playerManager.GetPlayer(conn)).UpdateResearchProgress(packet.TechId, packet.Hashes); Log.Debug($"ProcessPacket researchContribution: playerid by: {playerManager.GetPlayer(conn).Id} - hashes {packet.Hashes}"); } } diff --git a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryResearchUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryResearchUpdateProcessor.cs index e7c7bd5d4..4b37ad6ba 100644 --- a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryResearchUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryResearchUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.GameHistory; diff --git a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryTechRefundProcessor.cs b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryTechRefundProcessor.cs index d93277df9..506267f5d 100644 --- a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryTechRefundProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryTechRefundProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.GameHistory; diff --git a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryUnlockTechProcessor.cs b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryUnlockTechProcessor.cs index 152aa0050..551b66ad4 100644 --- a/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryUnlockTechProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameHistory/GameHistoryUnlockTechProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/GameStates/GameStateUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/GameStates/GameStateUpdateProcessor.cs index 60f23a8cf..2cf8d23e1 100644 --- a/NebulaNetwork/PacketProcessors/GameStates/GameStateUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/GameStates/GameStateUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.DataStructures; using NebulaModel.Logger; using NebulaModel.Networking; diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSAddStationComponentProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSAddStationComponentProcessor.cs index 18da62da2..e857ce8f0 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSAddStationComponentProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSAddStationComponentProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSArriveStarPlanetRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSArriveStarPlanetRequestProcessor.cs index d5a7f973b..27cbd70dc 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSArriveStarPlanetRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSArriveStarPlanetRequestProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -26,7 +27,7 @@ public override void ProcessPacket(ILSArriveStarPlanetRequest packet, NebulaConn { if (IsClient) return; - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player == null) { player = playerManager.GetSyncingPlayer(conn); diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSArriveStarPlanetResponseProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSArriveStarPlanetResponseProcessor.cs index fd3514f4b..3e5c3f4c4 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSArriveStarPlanetResponseProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSArriveStarPlanetResponseProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Logistics; diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSEnergyConsumeNotificationProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSEnergyConsumeNotificationProcessor.cs index 252e111de..d81bd7771 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSEnergyConsumeNotificationProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSEnergyConsumeNotificationProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Logistics; diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSRemoteOrderProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSRemoteOrderProcessor.cs index 622b7ef68..2404b2616 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSRemoteOrderProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSRemoteOrderProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -21,7 +22,7 @@ public override void ProcessPacket(ILSRemoteOrderData packet, NebulaConnection c { if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSRemoveStationComponentProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSRemoveStationComponentProcessor.cs index b0b5486f7..481b66970 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSRemoveStationComponentProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSRemoveStationComponentProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Logistics; diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSRequestShipDockProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSRequestShipDockProcessor.cs index 65bea394d..d10db88ba 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSRequestShipDockProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSRequestShipDockProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.DataStructures; using NebulaModel.Networking; @@ -28,7 +29,7 @@ public override void ProcessPacket(ILSRequestShipDock packet, NebulaConnection c { if (IsClient) return; - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player == null) { diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSResponseShipDockProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSResponseShipDockProcessor.cs index e7ecbdce7..85c27c936 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSResponseShipDockProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSResponseShipDockProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.DataStructures; using NebulaModel.Networking; using NebulaModel.Packets; @@ -24,8 +24,8 @@ public override void ProcessPacket(ILSShipDock packet, NebulaConnection conn) // a fake entry should already have been created StationComponent stationComponent = GameMain.data.galacticTransport.stationPool[packet.stationGId]; - stationComponent.shipDockPos = DataStructureExtensions.ToVector3(packet.shipDockPos); - stationComponent.shipDockRot = DataStructureExtensions.ToQuaternion(packet.shipDockRot); + stationComponent.shipDockPos = packet.shipDockPos.ToVector3(); + stationComponent.shipDockRot = packet.shipDockRot.ToQuaternion(); for (int i = 0; i < Multiplayer.Session.Ships.ILSMaxShipCount; i++) { @@ -50,10 +50,10 @@ public override void ProcessPacket(ILSShipDock packet, NebulaConnection conn) { stationComponent = GameMain.data.galacticTransport.stationPool[packet.shipOtherGId[i]]; - stationComponent.workShipDatas[packet.shipIndex[i]].uPos = DataStructureExtensions.ToVectorLF3(packet.shipPos[i]); - stationComponent.workShipDatas[packet.shipIndex[i]].uRot = DataStructureExtensions.ToQuaternion(packet.shipRot[i]); - stationComponent.workShipDatas[packet.shipIndex[i]].pPosTemp = DataStructureExtensions.ToVectorLF3(packet.shipPPosTemp[i]); - stationComponent.workShipDatas[packet.shipIndex[i]].pRotTemp = DataStructureExtensions.ToQuaternion(packet.shipPRotTemp[i]); + stationComponent.workShipDatas[packet.shipIndex[i]].uPos = packet.shipPos[i].ToVectorLF3(); + stationComponent.workShipDatas[packet.shipIndex[i]].uRot = packet.shipRot[i].ToQuaternion(); + stationComponent.workShipDatas[packet.shipIndex[i]].pPosTemp = packet.shipPPosTemp[i].ToVectorLF3(); + stationComponent.workShipDatas[packet.shipIndex[i]].pRotTemp = packet.shipPRotTemp[i].ToQuaternion(); } } } diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSShipDataUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSShipDataUpdateProcessor.cs index 283902e26..3f1e77226 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSShipDataUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSShipDataUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Logistics; diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSShipItemsProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSShipItemsProcessor.cs index 80051459f..4cdae6f26 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSShipItemsProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSShipItemsProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -19,7 +20,7 @@ public override void ProcessPacket(ILSShipItems packet, NebulaConnection conn) { if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSShipProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSShipProcessor.cs index 2c299eb04..4b5625983 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSShipProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSShipProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -22,7 +23,7 @@ public override void ProcessPacket(ILSShipData packet, NebulaConnection conn) { if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSShipUpdateWarperCntProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSShipUpdateWarperCntProcessor.cs index e00ce4e4c..9659db8fe 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSShipUpdateWarperCntProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSShipUpdateWarperCntProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Logistics; diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSUpdateSlotDataProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSUpdateSlotDataProcessor.cs index 15f3bc9d3..c14354158 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSUpdateSlotDataProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSUpdateSlotDataProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSgStationPoolSyncProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSgStationPoolSyncProcessor.cs index 0d3dd7435..ee239b4ed 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSgStationPoolSyncProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSgStationPoolSyncProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.DataStructures; using NebulaModel.Networking; using NebulaModel.Packets; @@ -27,9 +27,9 @@ public override void ProcessPacket(ILSgStationPoolSync packet, NebulaConnection Multiplayer.Session.Ships.CreateFakeStationComponent(packet.stationGId[i], packet.planetId[i], false); // handles array resizing gStationPool = GameMain.data.galacticTransport.stationPool; // dont remove or you get an ArrayOutOfBounds - gStationPool[packet.stationGId[i]].shipDockPos = DataStructureExtensions.ToVector3(packet.DockPos[i]); + gStationPool[packet.stationGId[i]].shipDockPos = packet.DockPos[i].ToVector3(); - gStationPool[packet.stationGId[i]].shipDockRot = DataStructureExtensions.ToQuaternion(packet.DockRot[i]); + gStationPool[packet.stationGId[i]].shipDockRot = packet.DockRot[i].ToQuaternion(); gStationPool[packet.stationGId[i]].id = packet.stationId[i]; gStationPool[packet.stationGId[i]].planetId = packet.planetId[i]; @@ -73,13 +73,13 @@ public override void ProcessPacket(ILSgStationPoolSync packet, NebulaConnection shipData.t = packet.shipT[i]; shipData.shipIndex = packet.shipIndex[i]; - shipData.uPos = DataStructureExtensions.ToVectorLF3(packet.shipPos[i]); - shipData.uRot = DataStructureExtensions.ToQuaternion(packet.shipRot[i]); - shipData.uVel = DataStructureExtensions.ToVector3(packet.shipVel[i]); + shipData.uPos = packet.shipPos[i].ToVectorLF3(); + shipData.uRot = packet.shipRot[i].ToQuaternion(); + shipData.uVel = packet.shipVel[i].ToVector3(); shipData.uSpeed = packet.shipSpeed[i]; - shipData.uAngularVel = DataStructureExtensions.ToVector3(packet.shipAngularVel[i]); - shipData.pPosTemp = DataStructureExtensions.ToVectorLF3(packet.shipPPosTemp[i]); - shipData.pRotTemp = DataStructureExtensions.ToQuaternion(packet.shipPRotTemp[i]); + shipData.uAngularVel = packet.shipAngularVel[i].ToVector3(); + shipData.pPosTemp = packet.shipPPosTemp[i].ToVectorLF3(); + shipData.pRotTemp = packet.shipRot[i].ToQuaternion(); gStationPool[packet.shipStationGId[i]].workShipDatas[i % Multiplayer.Session.Ships.ILSMaxShipCount] = shipData; } diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSgStationPoolSyncRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSgStationPoolSyncRequestProcessor.cs index 32065dabf..9071cf8e5 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSgStationPoolSyncRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSgStationPoolSyncRequestProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.DataStructures; using NebulaModel.Networking; @@ -25,7 +26,7 @@ public override void ProcessPacket(ILSRequestgStationPoolSync packet, NebulaConn { if (IsClient) return; - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player == null) { player = playerManager.GetSyncingPlayer(conn); diff --git a/NebulaNetwork/PacketProcessors/Logistics/StationSubscribeUIUpdatesProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/StationSubscribeUIUpdatesProcessor.cs index 3c22c64c2..0b7548e38 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/StationSubscribeUIUpdatesProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/StationSubscribeUIUpdatesProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Logistics; diff --git a/NebulaNetwork/PacketProcessors/Logistics/StationUIInitialSyncProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/StationUIInitialSyncProcessor.cs index 3890af77b..47032fc67 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/StationUIInitialSyncProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/StationUIInitialSyncProcessor.cs @@ -1,5 +1,4 @@ -using HarmonyLib; -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/Logistics/StationUIInitialSyncRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/StationUIInitialSyncRequestProcessor.cs index 7d687a01c..b54c88ece 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/StationUIInitialSyncRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/StationUIInitialSyncRequestProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/Logistics/StationUIProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/StationUIProcessor.cs index 76fc8e8f9..4761ac96c 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/StationUIProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/StationUIProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -34,8 +35,8 @@ public override void ProcessPacket(StationUI packet, NebulaConnection conn) { foreach (var kvp in connectedPlayers) { - NebulaPlayer p = kvp.Value; - packet.ShouldMimic = p.Connection == conn; + INebulaPlayer p = kvp.Value; + packet.ShouldMimic = ((NebulaConnection)p.Connection) == conn; p.SendPacket(packet); } } @@ -43,7 +44,7 @@ public override void ProcessPacket(StationUI packet, NebulaConnection conn) else if (packet.SettingIndex == StationUI.EUISettings.AddOrRemoveItemFromStorageResponse) { // if someone adds or removes items by hand broadcast to every player on that planet - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToPlanet(packet, player.Data.LocalPlanetId); diff --git a/NebulaNetwork/PacketProcessors/Planet/FactoryDataProcessor.cs b/NebulaNetwork/PacketProcessors/Planet/FactoryDataProcessor.cs index 389ccff14..7f56cd105 100644 --- a/NebulaNetwork/PacketProcessors/Planet/FactoryDataProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Planet/FactoryDataProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Planet; diff --git a/NebulaNetwork/PacketProcessors/Planet/FactoryLoadRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Planet/FactoryLoadRequestProcessor.cs index 02e8503af..6b67ea828 100644 --- a/NebulaNetwork/PacketProcessors/Planet/FactoryLoadRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Planet/FactoryLoadRequestProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Planet; diff --git a/NebulaNetwork/PacketProcessors/Planet/PlanetDataRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Planet/PlanetDataRequestProcessor.cs index 2667a463b..b5a1a4639 100644 --- a/NebulaNetwork/PacketProcessors/Planet/PlanetDataRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Planet/PlanetDataRequestProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/Planet/PlanetDataResponseProcessor.cs b/NebulaNetwork/PacketProcessors/Planet/PlanetDataResponseProcessor.cs index 58dcea03d..fb5119605 100644 --- a/NebulaNetwork/PacketProcessors/Planet/PlanetDataResponseProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Planet/PlanetDataResponseProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/Planet/VegeMinedProcessor.cs b/NebulaNetwork/PacketProcessors/Planet/VegeMinedProcessor.cs index 9dd93ef77..0229e8b30 100644 --- a/NebulaNetwork/PacketProcessors/Planet/VegeMinedProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Planet/VegeMinedProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel.Attributes; +using NebulaAPI; +using NebulaModel.Attributes; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs b/NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs index cc968bec0..923971935 100644 --- a/NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -25,7 +26,7 @@ public override void ProcessPacket(NewDroneOrderPacket packet, NebulaConnection if (GameMain.mainPlayer.planetId != packet.PlanetId) return; - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { if (packet.Stage == 1 || packet.Stage == 2) diff --git a/NebulaNetwork/PacketProcessors/Players/PlayerAnimationUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Players/PlayerAnimationUpdateProcessor.cs index 2a9a5c0cc..0739036a0 100644 --- a/NebulaNetwork/PacketProcessors/Players/PlayerAnimationUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Players/PlayerAnimationUpdateProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -23,7 +24,7 @@ public override void ProcessPacket(PlayerAnimationUpdate packet, NebulaConnectio if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { packet.PlayerId = player.Id; diff --git a/NebulaNetwork/PacketProcessors/Players/PlayerColorChangedProcessor.cs b/NebulaNetwork/PacketProcessors/Players/PlayerColorChangedProcessor.cs index 2f48bae3d..f5fb499a2 100644 --- a/NebulaNetwork/PacketProcessors/Players/PlayerColorChangedProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Players/PlayerColorChangedProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -23,7 +24,7 @@ public override void ProcessPacket(PlayerColorChanged packet, NebulaConnection c if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { player.Data.MechaColor = packet.Color; diff --git a/NebulaNetwork/PacketProcessors/Players/PlayerMechaDataProcessor.cs b/NebulaNetwork/PacketProcessors/Players/PlayerMechaDataProcessor.cs index a7e68a0a2..4a18820ca 100644 --- a/NebulaNetwork/PacketProcessors/Players/PlayerMechaDataProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Players/PlayerMechaDataProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/Players/PlayerMovementProcessor.cs b/NebulaNetwork/PacketProcessors/Players/PlayerMovementProcessor.cs index e8a08603e..456217e52 100644 --- a/NebulaNetwork/PacketProcessors/Players/PlayerMovementProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Players/PlayerMovementProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -22,7 +23,7 @@ public override void ProcessPacket(PlayerMovement packet, NebulaConnection conn) bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { player.Data.LocalPlanetId = packet.LocalPlanetId; diff --git a/NebulaNetwork/PacketProcessors/Players/PlayerUpdateLocalStarIdProcessor.cs b/NebulaNetwork/PacketProcessors/Players/PlayerUpdateLocalStarIdProcessor.cs index 457ad9104..bbdd5815a 100644 --- a/NebulaNetwork/PacketProcessors/Players/PlayerUpdateLocalStarIdProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Players/PlayerUpdateLocalStarIdProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -21,7 +22,7 @@ public override void ProcessPacket(PlayerUpdateLocalStarId packet, NebulaConnect { if (IsClient) return; - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { player.Data.LocalStarId = packet.StarId; diff --git a/NebulaNetwork/PacketProcessors/Players/PlayerUseWarperProcessor.cs b/NebulaNetwork/PacketProcessors/Players/PlayerUseWarperProcessor.cs index 4eda6eaf4..d3126569c 100644 --- a/NebulaNetwork/PacketProcessors/Players/PlayerUseWarperProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Players/PlayerUseWarperProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -23,7 +24,7 @@ public override void ProcessPacket(PlayerUseWarper packet, NebulaConnection conn bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { packet.PlayerId = player.Id; diff --git a/NebulaNetwork/PacketProcessors/Routers/PlanetBroadcastProcessor.cs b/NebulaNetwork/PacketProcessors/Routers/PlanetBroadcastProcessor.cs index c99719bc0..28d7c0836 100644 --- a/NebulaNetwork/PacketProcessors/Routers/PlanetBroadcastProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Routers/PlanetBroadcastProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -19,13 +20,13 @@ public override void ProcessPacket(PlanetBroadcastPacket packet, NebulaConnectio { if (IsClient) return; - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { //Forward packet to other users playerManager.SendRawPacketToPlanet(packet.PacketObject, packet.PlanetId, conn); //Forward packet to the host - Multiplayer.Session.Network.PacketProcessor.EnqueuePacketForProcessing(packet.PacketObject, conn); + ((NetworkProvider)Multiplayer.Session.Network).PacketProcessor.EnqueuePacketForProcessing(packet.PacketObject, conn); } } } diff --git a/NebulaNetwork/PacketProcessors/Routers/StarBroadcastProcessor.cs b/NebulaNetwork/PacketProcessors/Routers/StarBroadcastProcessor.cs index 1372abfbc..36fa319ef 100644 --- a/NebulaNetwork/PacketProcessors/Routers/StarBroadcastProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Routers/StarBroadcastProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -19,12 +20,12 @@ public override void ProcessPacket(StarBroadcastPacket packet, NebulaConnection { if (IsClient) return; - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { //Forward packet to other users playerManager.SendRawPacketToStar(packet.PacketObject, packet.StarId, conn); - Multiplayer.Session.Network.PacketProcessor.EnqueuePacketForProcessing(packet.PacketObject, conn); + ((NetworkProvider)Multiplayer.Session.Network).PacketProcessor.EnqueuePacketForProcessing(packet.PacketObject, conn); } } } diff --git a/NebulaNetwork/PacketProcessors/Session/HandshakeRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Session/HandshakeRequestProcessor.cs index fd25b3419..b83f2b84e 100644 --- a/NebulaNetwork/PacketProcessors/Session/HandshakeRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Session/HandshakeRequestProcessor.cs @@ -1,5 +1,7 @@ -using NebulaModel; -using NebulaModel.Attributes; +using BepInEx; +using NebulaAPI; +using NebulaModel; +using NebulaModel.DataStructures; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; @@ -7,6 +9,8 @@ using NebulaModel.Packets.Session; using NebulaModel.Utils; using NebulaWorld; +using System.Collections.Generic; +using LocalPlayer = NebulaWorld.LocalPlayer; namespace NebulaNetwork.PacketProcessors.Session { @@ -24,7 +28,7 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con { if (IsClient) return; - NebulaPlayer player; + INebulaPlayer player; using (playerManager.GetPendingPlayers(out var pendingPlayers)) { if (!pendingPlayers.TryGetValue(conn, out player)) @@ -36,12 +40,42 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con pendingPlayers.Remove(conn); } + + Dictionary clientMods = new Dictionary(); + using (BinaryUtils.Reader reader = new BinaryUtils.Reader(packet.ModsVersion)) + { + for (int i = 0; i < packet.ModsCount; i++) + { + string guid = reader.BinaryReader.ReadString(); + string version = reader.BinaryReader.ReadString(); + + if (!BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey(guid)) + { + conn.Disconnect(DisconnectionReason.ModIsMissingOnServer, guid); + } + + clientMods.Add(guid, version); + } + } - if (packet.ModVersion != Config.ModVersion) + foreach (var pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) { - conn.Disconnect(DisconnectionReason.ModVersionMismatch, $"{ packet.ModVersion };{ Config.ModVersion }"); - return; + if (pluginInfo.Value.Instance is IMultiplayerMod mod) + { + if (!clientMods.ContainsKey(pluginInfo.Key)) + { + conn.Disconnect(DisconnectionReason.ModIsMissing, pluginInfo.Key); + return; + } + + string version = clientMods[pluginInfo.Key]; + + if (mod.CheckVersion(mod.Version, version)) continue; + + conn.Disconnect(DisconnectionReason.ModVersionMismatch, $"{pluginInfo.Key};{version};{mod.Version}"); + return; + } } if (packet.GameVersionSig != GameConfig.gameVersion.sig) @@ -77,7 +111,7 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con player.Data.MechaColor = packet.MechaColor; // Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter - PlayerJoining pdata = new PlayerJoining(player.Data.CreateCopyWithoutMechaData()); // Remove inventory from mecha data + PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData()); // Remove inventory from mecha data using (playerManager.GetConnectedPlayers(out var connectedPlayers)) { foreach (var kvp in connectedPlayers) @@ -93,10 +127,24 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con } //Add current tech bonuses to the connecting player based on the Host's mecha - player.Data.Mecha.TechBonuses = new PlayerTechBonuses(GameMain.mainPlayer.mecha); + ((MechaData)player.Data.Mecha).TechBonuses = new PlayerTechBonuses(GameMain.mainPlayer.mecha); - var gameDesc = GameMain.data.gameDesc; - player.SendPacket(new HandshakeResponse(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, gameDesc.resourceMultiplier, isNewUser, player.Data)); + using (BinaryUtils.Writer p = new BinaryUtils.Writer()) + { + int count = 0; + foreach (var pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) + { + if (pluginInfo.Value.Instance is IMultiplayerModWithSettings mod) + { + p.BinaryWriter.Write(pluginInfo.Key); + mod.Export(p.BinaryWriter); + count++; + } + } + + var gameDesc = GameMain.data.gameDesc; + player.SendPacket(new HandshakeResponse(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, gameDesc.resourceMultiplier, isNewUser, (PlayerData)player.Data, p.CloseAndGetBytes(), count)); + } } } -} +} \ No newline at end of file diff --git a/NebulaNetwork/PacketProcessors/Session/HandshakeResponseProcessor.cs b/NebulaNetwork/PacketProcessors/Session/HandshakeResponseProcessor.cs index 277b3e64a..087afd1fe 100644 --- a/NebulaNetwork/PacketProcessors/Session/HandshakeResponseProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Session/HandshakeResponseProcessor.cs @@ -1,4 +1,6 @@ -using NebulaModel.Attributes; +using BepInEx; +using BepInEx.Bootstrap; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Session; @@ -11,8 +13,20 @@ public class HandshakeResponseProcessor : PacketProcessor { public override void ProcessPacket(HandshakeResponse packet, NebulaConnection conn) { - Multiplayer.Session.LocalPlayer.IsHost = false; - Multiplayer.Session.LocalPlayer.SetPlayerData(packet.LocalPlayerData, packet.IsNewPlayer); + using (BinaryUtils.Reader p = new BinaryUtils.Reader(packet.ModsSettings)) + { + for (int i = 0; i < packet.ModsSettingsCount; i++) + { + string guid = p.BinaryReader.ReadString(); + PluginInfo info = Chainloader.PluginInfos[guid]; + if (info.Instance is IMultiplayerModWithSettings mod) + { + mod.Import(p.BinaryReader); + } + } + } + ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false; + ((LocalPlayer)Multiplayer.Session.LocalPlayer).SetPlayerData(packet.LocalPlayerData, packet.IsNewPlayer); GameDesc gameDesc = new GameDesc(); gameDesc.SetForNewGame(packet.AlgoVersion, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier); diff --git a/NebulaNetwork/PacketProcessors/Session/PingPacketProcessor.cs b/NebulaNetwork/PacketProcessors/Session/PingPacketProcessor.cs index 3ac399d74..f16933429 100644 --- a/NebulaNetwork/PacketProcessors/Session/PingPacketProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Session/PingPacketProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Session; diff --git a/NebulaNetwork/PacketProcessors/Session/PlayerDisconnectedProcessor.cs b/NebulaNetwork/PacketProcessors/Session/PlayerDisconnectedProcessor.cs index 19bde23ea..281d01248 100644 --- a/NebulaNetwork/PacketProcessors/Session/PlayerDisconnectedProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Session/PlayerDisconnectedProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Session; diff --git a/NebulaNetwork/PacketProcessors/Session/PlayerJoiningProcessor.cs b/NebulaNetwork/PacketProcessors/Session/PlayerJoiningProcessor.cs index d50d2f212..7fb011080 100644 --- a/NebulaNetwork/PacketProcessors/Session/PlayerJoiningProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Session/PlayerJoiningProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Session; diff --git a/NebulaNetwork/PacketProcessors/Session/SyncCompleteProcessor.cs b/NebulaNetwork/PacketProcessors/Session/SyncCompleteProcessor.cs index daf73cca4..fee61c479 100644 --- a/NebulaNetwork/PacketProcessors/Session/SyncCompleteProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Session/SyncCompleteProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Logger; using NebulaModel.Networking; @@ -6,7 +7,8 @@ using NebulaModel.Packets.Session; using NebulaModel.Packets.Universe; using NebulaWorld; -using NebulaWorld.Factory; +using FactoryManager = NebulaWorld.Factory.FactoryManager; +using LocalPlayer = NebulaWorld.LocalPlayer; namespace NebulaNetwork.PacketProcessors.Session { @@ -24,7 +26,7 @@ public override void ProcessPacket(SyncComplete packet, NebulaConnection conn) { if (IsHost) { - NebulaPlayer player = playerManager.GetSyncingPlayer(conn); + INebulaPlayer player = playerManager.GetSyncingPlayer(conn); if (player == null) { Log.Warn("Received a SyncComplete packet, but no player is joining."); @@ -50,14 +52,14 @@ public override void ProcessPacket(SyncComplete packet, NebulaConnection conn) { if (!string.IsNullOrEmpty(s.overrideName)) { - player.SendPacket(new NameInputPacket(s.overrideName, s.id, FactoryManager.PLANET_NONE, Multiplayer.Session.LocalPlayer.Id)); + player.SendPacket(new NameInputPacket(s.overrideName, s.id, NebulaModAPI.PLANET_NONE, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id)); } foreach (PlanetData p in s.planets) { if (!string.IsNullOrEmpty(p.overrideName)) { - player.SendPacket(new NameInputPacket(p.overrideName, FactoryManager.STAR_NONE, p.id, Multiplayer.Session.LocalPlayer.Id)); + player.SendPacket(new NameInputPacket(p.overrideName, NebulaModAPI.STAR_NONE, p.id, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id)); } } } @@ -77,7 +79,7 @@ public override void ProcessPacket(SyncComplete packet, NebulaConnection conn) // Everyone is now connected, we can safely spawn the player model of all the other players that are currently connected foreach (var playerData in packet.AllPlayers) { - if (playerData.PlayerId != Multiplayer.Session.LocalPlayer.Id) + if (playerData.PlayerId != ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id) { Multiplayer.Session.World.SpawnRemotePlayerModel(playerData); } diff --git a/NebulaNetwork/PacketProcessors/Statistics/StatisticsDataProcessor.cs b/NebulaNetwork/PacketProcessors/Statistics/StatisticsDataProcessor.cs index dd4ce615c..9605707fa 100644 --- a/NebulaNetwork/PacketProcessors/Statistics/StatisticsDataProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Statistics/StatisticsDataProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Statistics; diff --git a/NebulaNetwork/PacketProcessors/Statistics/StatisticsPlanetDataProcessor.cs b/NebulaNetwork/PacketProcessors/Statistics/StatisticsPlanetDataProcessor.cs index 3e0731e37..12de491c7 100644 --- a/NebulaNetwork/PacketProcessors/Statistics/StatisticsPlanetDataProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Statistics/StatisticsPlanetDataProcessor.cs @@ -1,5 +1,4 @@ -using HarmonyLib; -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Statistics; diff --git a/NebulaNetwork/PacketProcessors/Statistics/StatisticsRequestEventProcessor.cs b/NebulaNetwork/PacketProcessors/Statistics/StatisticsRequestEventProcessor.cs index 47323c252..1afa0dc90 100644 --- a/NebulaNetwork/PacketProcessors/Statistics/StatisticsRequestEventProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Statistics/StatisticsRequestEventProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -21,7 +22,7 @@ public override void ProcessPacket(StatisticsRequestEvent packet, NebulaConnecti { if (IsClient) return; - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { if (packet.Event == StatisticEvent.WindowOpened) diff --git a/NebulaNetwork/PacketProcessors/Statistics/StatisticsUpdateProcessor.cs b/NebulaNetwork/PacketProcessors/Statistics/StatisticsUpdateProcessor.cs index 9ed847eaf..6000a29f3 100644 --- a/NebulaNetwork/PacketProcessors/Statistics/StatisticsUpdateProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Statistics/StatisticsUpdateProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.DataStructures; using NebulaModel.Networking; using NebulaModel.Packets; diff --git a/NebulaNetwork/PacketProcessors/Trash/TrashSystemClearAllTrashProcessor.cs b/NebulaNetwork/PacketProcessors/Trash/TrashSystemClearAllTrashProcessor.cs index 734577efe..6f49d1172 100644 --- a/NebulaNetwork/PacketProcessors/Trash/TrashSystemClearAllTrashProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Trash/TrashSystemClearAllTrashProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -23,7 +24,7 @@ public override void ProcessPacket(TrashSystemClearAllTrashPacket packet, Nebula bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); diff --git a/NebulaNetwork/PacketProcessors/Trash/TrashSystemCorrectionIdProcessor.cs b/NebulaNetwork/PacketProcessors/Trash/TrashSystemCorrectionIdProcessor.cs index 44b3c6aa4..115be4fd2 100644 --- a/NebulaNetwork/PacketProcessors/Trash/TrashSystemCorrectionIdProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Trash/TrashSystemCorrectionIdProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Trash; diff --git a/NebulaNetwork/PacketProcessors/Trash/TrashSystemNewTrashCreatedProcessor.cs b/NebulaNetwork/PacketProcessors/Trash/TrashSystemNewTrashCreatedProcessor.cs index be52bf2c9..6cc5a8ffb 100644 --- a/NebulaNetwork/PacketProcessors/Trash/TrashSystemNewTrashCreatedProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Trash/TrashSystemNewTrashCreatedProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -23,7 +24,7 @@ public override void ProcessPacket(TrashSystemNewTrashCreatedPacket packet, Nebu bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); diff --git a/NebulaNetwork/PacketProcessors/Trash/TrashSystemRequestDataProcessor.cs b/NebulaNetwork/PacketProcessors/Trash/TrashSystemRequestDataProcessor.cs index 46ac38dce..c25ae6771 100644 --- a/NebulaNetwork/PacketProcessors/Trash/TrashSystemRequestDataProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Trash/TrashSystemRequestDataProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Trash; diff --git a/NebulaNetwork/PacketProcessors/Trash/TrashSystemResponseDataProcessor.cs b/NebulaNetwork/PacketProcessors/Trash/TrashSystemResponseDataProcessor.cs index 8df8206ba..eb34d78d6 100644 --- a/NebulaNetwork/PacketProcessors/Trash/TrashSystemResponseDataProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Trash/TrashSystemResponseDataProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Trash; diff --git a/NebulaNetwork/PacketProcessors/Trash/TrashSystemTrashRemovedProcessor.cs b/NebulaNetwork/PacketProcessors/Trash/TrashSystemTrashRemovedProcessor.cs index 695078843..6873e8445 100644 --- a/NebulaNetwork/PacketProcessors/Trash/TrashSystemTrashRemovedProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Trash/TrashSystemTrashRemovedProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -24,7 +25,7 @@ public override void ProcessPacket(TrashSystemTrashRemovedPacket packet, NebulaC if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddFrameProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddFrameProcessor.cs index e3221821f..e147acb02 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddFrameProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddFrameProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -23,7 +24,7 @@ public override void ProcessPacket(DysonSphereAddFramePacket packet, NebulaConne if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddLayerProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddLayerProcessor.cs index e91f6efce..b3a9077bf 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddLayerProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddLayerProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.DataStructures; using NebulaModel.Networking; @@ -23,7 +24,7 @@ public override void ProcessPacket(DysonSphereAddLayerPacket packet, NebulaConne bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else @@ -34,7 +35,7 @@ public override void ProcessPacket(DysonSphereAddLayerPacket packet, NebulaConne { using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On()) { - GameMain.data.dysonSpheres[packet.StarIndex]?.AddLayer(packet.OrbitRadius, DataStructureExtensions.ToQuaternion(packet.OrbitRotation), packet.OrbitAngularSpeed); + GameMain.data.dysonSpheres[packet.StarIndex]?.AddLayer(packet.OrbitRadius, packet.OrbitRotation.ToQuaternion(), packet.OrbitAngularSpeed); } } } diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddNodeProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddNodeProcessor.cs index 9602f17fa..cd6a004fe 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddNodeProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddNodeProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.DataStructures; using NebulaModel.Networking; @@ -23,7 +24,7 @@ public override void ProcessPacket(DysonSphereAddNodePacket packet, NebulaConnec bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else @@ -34,7 +35,7 @@ public override void ProcessPacket(DysonSphereAddNodePacket packet, NebulaConnec { using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On()) { - GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId)?.NewDysonNode(packet.NodeProtoId, DataStructureExtensions.ToVector3(packet.Position)); + GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId)?.NewDysonNode(packet.NodeProtoId, packet.Position.ToVector3()); // Try to add frames that failed due to the missing nodes DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddSailBulletProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddSailBulletProcessor.cs index a03a8c835..abe2f9525 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddSailBulletProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddSailBulletProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.DataStructures; using NebulaModel.Networking; using NebulaModel.Packets; @@ -16,8 +16,8 @@ public override void ProcessPacket(DysonSphereBulletCorrectionPacket packet, Neb { //Update destination values for the bullet SailBullet bullet = GameMain.data.dysonSpheres[packet.StarIndex].swarm.bulletPool[packet.BulletId]; - bullet.uEnd = DataStructureExtensions.ToVector3(packet.UEnd); - bullet.uEndVel = DataStructureExtensions.ToVector3(packet.UEndVel); + bullet.uEnd = packet.UEnd.ToVector3(); + bullet.uEndVel = packet.UEndVel.ToVector3(); } else { diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddShellProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddShellProcessor.cs index d7908a30a..10e56ab6c 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddShellProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereAddShellProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -24,7 +25,7 @@ public override void ProcessPacket(DysonSphereAddShellPacket packet, NebulaConne bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereDataProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereDataProcessor.cs index 8d35f922a..34dcf5eb6 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereDataProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereDataProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Universe; diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveFrameProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveFrameProcessor.cs index b652586d6..2f938c020 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveFrameProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveFrameProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -23,7 +24,7 @@ public override void ProcessPacket(DysonSphereRemoveFramePacket packet, NebulaCo bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveLayerProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveLayerProcessor.cs index 6d160dc26..526538b14 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveLayerProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveLayerProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -23,7 +24,7 @@ public override void ProcessPacket(DysonSphereRemoveLayerPacket packet, NebulaCo bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveNodeProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveNodeProcessor.cs index 08adc2fef..eab7c2a2a 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveNodeProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveNodeProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -23,7 +24,7 @@ public override void ProcessPacket(DysonSphereRemoveNodePacket packet, NebulaCon bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveShellProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveShellProcessor.cs index 23a51290f..06e8d58da 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveShellProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRemoveShellProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -22,7 +23,7 @@ public override void ProcessPacket(DysonSphereRemoveShellPacket packet, NebulaCo bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRequestProcessor.cs index f3c70ea3f..2fe3d7602 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSphereRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSphereRequestProcessor.cs @@ -1,4 +1,4 @@ -using NebulaModel.Attributes; +using NebulaAPI; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Universe; diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSwarmAddOrbitProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSwarmAddOrbitProcessor.cs index 8274be2f9..b35d6542d 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSwarmAddOrbitProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSwarmAddOrbitProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.DataStructures; using NebulaModel.Networking; @@ -23,7 +24,7 @@ public override void ProcessPacket(DysonSwarmAddOrbitPacket packet, NebulaConnec bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else @@ -34,7 +35,7 @@ public override void ProcessPacket(DysonSwarmAddOrbitPacket packet, NebulaConnec { using (Multiplayer.Session.DysonSpheres.IncomingDysonSwarmPacket.On()) { - GameMain.data.dysonSpheres[packet.StarIndex]?.swarm?.NewOrbit(packet.Radius, DataStructureExtensions.ToQuaternion(packet.Rotation)); + GameMain.data.dysonSpheres[packet.StarIndex]?.swarm?.NewOrbit(packet.Radius, packet.Rotation.ToQuaternion()); } } } diff --git a/NebulaNetwork/PacketProcessors/Universe/DysonSwarmRemoveOrbitProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/DysonSwarmRemoveOrbitProcessor.cs index 1ded54477..2099b6eb1 100644 --- a/NebulaNetwork/PacketProcessors/Universe/DysonSwarmRemoveOrbitProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/DysonSwarmRemoveOrbitProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -22,7 +23,7 @@ public override void ProcessPacket(DysonSwarmRemoveOrbitPacket packet, NebulaCon bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else diff --git a/NebulaNetwork/PacketProcessors/Universe/NameInputProcessor.cs b/NebulaNetwork/PacketProcessors/Universe/NameInputProcessor.cs index 27062f20e..8a3faf921 100644 --- a/NebulaNetwork/PacketProcessors/Universe/NameInputProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Universe/NameInputProcessor.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Attributes; using NebulaModel.Networking; using NebulaModel.Packets; @@ -26,7 +27,7 @@ public override void ProcessPacket(NameInputPacket packet, NebulaConnection conn bool valid = true; if (IsHost) { - NebulaPlayer player = playerManager.GetPlayer(conn); + INebulaPlayer player = playerManager.GetPlayer(conn); if (player != null) playerManager.SendPacketToOtherPlayers(packet, player); else @@ -37,7 +38,7 @@ public override void ProcessPacket(NameInputPacket packet, NebulaConnection conn { using (Multiplayer.Session.Factories.IsIncomingRequest.On()) { - if (packet.StarId != FactoryManager.STAR_NONE) + if (packet.StarId != NebulaModAPI.STAR_NONE) { var star = GameMain.galaxy.StarById(packet.StarId); star.overrideName = packet.Name; diff --git a/NebulaNetwork/PlayerManager.cs b/NebulaNetwork/PlayerManager.cs index db3a57132..fd7dc23b8 100644 --- a/NebulaNetwork/PlayerManager.cs +++ b/NebulaNetwork/PlayerManager.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.DataStructures; using NebulaModel.Logger; using NebulaModel.Networking; @@ -16,34 +17,34 @@ public class PlayerManager : IPlayerManager { sealed class ThreadSafe { - internal readonly Dictionary pendingPlayers = new Dictionary(); - internal readonly Dictionary syncingPlayers = new Dictionary(); - internal readonly Dictionary connectedPlayers = new Dictionary(); - internal readonly Dictionary savedPlayerData = new Dictionary(); + internal readonly Dictionary pendingPlayers = new Dictionary(); + internal readonly Dictionary syncingPlayers = new Dictionary(); + internal readonly Dictionary connectedPlayers = new Dictionary(); + internal readonly Dictionary savedPlayerData = new Dictionary(); internal readonly Queue availablePlayerIds = new Queue(); } private readonly ThreadSafe threadSafe = new ThreadSafe(); private int highestPlayerID = 0; - public Locker GetPendingPlayers(out Dictionary pendingPlayers) => + public Locker GetPendingPlayers(out Dictionary pendingPlayers) => threadSafe.pendingPlayers.GetLocked(out pendingPlayers); - public Locker GetSyncingPlayers(out Dictionary syncingPlayers) => + public Locker GetSyncingPlayers(out Dictionary syncingPlayers) => threadSafe.syncingPlayers.GetLocked(out syncingPlayers); - public Locker GetConnectedPlayers(out Dictionary connectedPlayers) => + public Locker GetConnectedPlayers(out Dictionary connectedPlayers) => threadSafe.connectedPlayers.GetLocked(out connectedPlayers); - public Locker GetSavedPlayerData(out Dictionary savedPlayerData) => + public Locker GetSavedPlayerData(out Dictionary savedPlayerData) => threadSafe.savedPlayerData.GetLocked(out savedPlayerData); - public PlayerData[] GetAllPlayerDataIncludingHost() + public IPlayerData[] GetAllPlayerDataIncludingHost() { using (GetConnectedPlayers(out var connectedPlayers)) { int i = 0; - var result = new PlayerData[1 + connectedPlayers.Count]; + var result = new IPlayerData[1 + connectedPlayers.Count]; result[i++] = Multiplayer.Session.LocalPlayer.Data; foreach (var kvp in connectedPlayers) { @@ -54,11 +55,11 @@ public PlayerData[] GetAllPlayerDataIncludingHost() } } - public NebulaPlayer GetPlayer(NebulaConnection conn) + public INebulaPlayer GetPlayer(INebulaConnection conn) { using (GetConnectedPlayers(out var connectedPlayers)) { - if (connectedPlayers.TryGetValue(conn, out NebulaPlayer player)) + if (connectedPlayers.TryGetValue(conn, out INebulaPlayer player)) { return player; } @@ -67,11 +68,11 @@ public NebulaPlayer GetPlayer(NebulaConnection conn) return null; } - public NebulaPlayer GetSyncingPlayer(NebulaConnection conn) + public INebulaPlayer GetSyncingPlayer(INebulaConnection conn) { using (GetSyncingPlayers(out var syncingPlayers)) { - if (syncingPlayers.TryGetValue(conn, out NebulaPlayer player)) + if (syncingPlayers.TryGetValue(conn, out INebulaPlayer player)) { return player; } @@ -86,7 +87,7 @@ public NebulaPlayer GetSyncingPlayer(NebulaConnection conn) { foreach (var kvp in connectedPlayers) { - NebulaPlayer player = kvp.Value; + INebulaPlayer player = kvp.Value; player.SendPacket(packet); } } @@ -153,7 +154,7 @@ public NebulaPlayer GetSyncingPlayer(NebulaConnection conn) } } - public void SendPacketToStarExcept(T packet, int starId, NebulaConnection exclude) where T : class, new() + public void SendPacketToStarExcept(T packet, int starId, INebulaConnection exclude) where T : class, new() { using (GetConnectedPlayers(out var connectedPlayers)) { @@ -168,7 +169,7 @@ public NebulaPlayer GetSyncingPlayer(NebulaConnection conn) } } - public void SendRawPacketToStar(byte[] rawPacket, int starId, NebulaConnection sender) + public void SendRawPacketToStar(byte[] rawPacket, int starId, INebulaConnection sender) { using (GetConnectedPlayers(out var connectedPlayers)) { @@ -177,13 +178,13 @@ public void SendRawPacketToStar(byte[] rawPacket, int starId, NebulaConnection s var player = kvp.Value; if (player.Data.LocalStarId == starId && player.Connection != sender) { - player.SendRawPacket(rawPacket); + ((NebulaPlayer)player).SendRawPacket(rawPacket); } } } } - public void SendRawPacketToPlanet(byte[] rawPacket, int planetId, NebulaConnection sender) + public void SendRawPacketToPlanet(byte[] rawPacket, int planetId, INebulaConnection sender) { using (GetConnectedPlayers(out var connectedPlayers)) { @@ -192,13 +193,13 @@ public void SendRawPacketToPlanet(byte[] rawPacket, int planetId, NebulaConnecti var player = kvp.Value; if (player.Data.LocalPlanetId == planetId && player.Connection != sender) { - player.SendRawPacket(rawPacket); + ((NebulaPlayer)player).SendRawPacket(rawPacket); } } } } - public void SendPacketToOtherPlayers(T packet, NebulaPlayer sender) where T : class, new() + public void SendPacketToOtherPlayers(T packet, INebulaPlayer sender) where T : class, new() { using (GetConnectedPlayers(out var connectedPlayers)) { @@ -213,7 +214,7 @@ public void SendRawPacketToPlanet(byte[] rawPacket, int planetId, NebulaConnecti } } - public NebulaPlayer PlayerConnected(NebulaConnection conn) + public INebulaPlayer PlayerConnected(INebulaConnection conn) { // Generate new data for the player ushort playerId = GetNextAvailablePlayerId(); @@ -222,7 +223,7 @@ public NebulaPlayer PlayerConnected(NebulaConnection conn) PlanetData birthPlanet = GameMain.galaxy.PlanetById(GameMain.galaxy.birthPlanetId); PlayerData playerData = new PlayerData(playerId, -1, playerColor, position: new Double3(birthPlanet.uPosition.x, birthPlanet.uPosition.y, birthPlanet.uPosition.z)); - NebulaPlayer newPlayer = new NebulaPlayer(conn, playerData); + INebulaPlayer newPlayer = new NebulaPlayer((NebulaConnection)conn, playerData); using (GetPendingPlayers(out var pendingPlayers)) { pendingPlayers.Add(conn, newPlayer); @@ -231,11 +232,11 @@ public NebulaPlayer PlayerConnected(NebulaConnection conn) return newPlayer; } - public void PlayerDisconnected(NebulaConnection conn) + public void PlayerDisconnected(INebulaConnection conn) { using (GetConnectedPlayers(out var connectedPlayers)) { - if (connectedPlayers.TryGetValue(conn, out NebulaPlayer player)) + if (connectedPlayers.TryGetValue(conn, out INebulaPlayer player)) { SendPacketToOtherPlayers(new PlayerDisconnected(player.Id), player); Multiplayer.Session.World.DestroyRemotePlayerModel(player.Id); @@ -281,7 +282,7 @@ public ushort GetNextAvailablePlayerId() return (ushort)Interlocked.Increment(ref highestPlayerID); // this is truncated to ushort.MaxValue } - public void UpdateMechaData(MechaData mechaData, NebulaConnection conn) + public void UpdateMechaData(IMechaData mechaData, INebulaConnection conn) { if (mechaData == null) { @@ -289,7 +290,7 @@ public void UpdateMechaData(MechaData mechaData, NebulaConnection conn) } using (GetConnectedPlayers(out var connectedPlayers)) { - if (connectedPlayers.TryGetValue(conn, out NebulaPlayer player)) + if (connectedPlayers.TryGetValue(conn, out INebulaPlayer player)) { //Find correct player for data to update player.Data.Mecha = mechaData; @@ -304,8 +305,8 @@ public void SendTechRefundPackagesToClients(int techId) { foreach (var kvp in connectedPlayers) { - NebulaPlayer curPlayer = kvp.Value; - long techProgress = curPlayer.ReleaseResearchProgress(); + INebulaPlayer curPlayer = kvp.Value; + long techProgress = ((NebulaPlayer)curPlayer).ReleaseResearchProgress(); if (techProgress > 0) { diff --git a/NebulaNetwork/SaveManager.cs b/NebulaNetwork/SaveManager.cs index 95d077701..4a23fe251 100644 --- a/NebulaNetwork/SaveManager.cs +++ b/NebulaNetwork/SaveManager.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel; using NebulaModel.DataStructures; using NebulaModel.Networking.Serialization; @@ -23,7 +24,7 @@ public static void SaveServerData(string saveName) { netDataWriter.Put(savedPlayerData.Count + 1); //Add data about all players - foreach (KeyValuePair data in savedPlayerData) + foreach (KeyValuePair data in savedPlayerData) { string hash = data.Key; netDataWriter.Put(hash); @@ -33,7 +34,7 @@ public static void SaveServerData(string saveName) //Add host's data netDataWriter.Put(CryptoUtils.GetCurrentUserPublicKeyHash()); - Multiplayer.Session.LocalPlayer.Data.Serialize(netDataWriter); + ((LocalPlayer)Multiplayer.Session.LocalPlayer).Data.Serialize(netDataWriter); File.WriteAllBytes(path, netDataWriter.Data); diff --git a/NebulaNetwork/Server.cs b/NebulaNetwork/Server.cs index 43e49ac42..e0dd20da0 100644 --- a/NebulaNetwork/Server.cs +++ b/NebulaNetwork/Server.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel; using NebulaModel.DataStructures; using NebulaModel.Networking; @@ -9,6 +10,7 @@ using NebulaWorld; using System; using System.Net.Sockets; +using System.Reflection; using UnityEngine; using WebSocketSharp; using WebSocketSharp.Server; @@ -43,8 +45,17 @@ public override void Start() SaveManager.LoadServerData(); } - PacketUtils.RegisterAllPacketNestedTypes(PacketProcessor); + foreach (Assembly assembly in AssembliesUtils.GetNebulaAssemblies()) + { + PacketUtils.RegisterAllPacketNestedTypesInAssembly(assembly, PacketProcessor); + } PacketUtils.RegisterAllPacketProcessorsInCallingAssembly(PacketProcessor, true); + + foreach (Assembly assembly in NebulaModAPI.TargetAssemblies) + { + PacketUtils.RegisterAllPacketNestedTypesInAssembly(assembly, PacketProcessor); + PacketUtils.RegisterAllPacketProcessorsInAssembly(assembly, PacketProcessor, true); + } #if DEBUG PacketProcessor.SimulateLatency = true; #endif @@ -54,18 +65,22 @@ public override void Start() socket.AddWebSocketService("/socket", () => new WebSocketService(PlayerManager, PacketProcessor)); socket.Start(); - Multiplayer.Session.LocalPlayer.IsHost = true; + ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = true; - Multiplayer.Session.LocalPlayer.SetPlayerData(new PlayerData( + ((LocalPlayer)Multiplayer.Session.LocalPlayer).SetPlayerData(new PlayerData( PlayerManager.GetNextAvailablePlayerId(), GameMain.localPlanet?.id ?? -1, new Float3(Config.Options.MechaColorR / 255, Config.Options.MechaColorG / 255, Config.Options.MechaColorB / 255), !string.IsNullOrWhiteSpace(Config.Options.Nickname) ? Config.Options.Nickname : GameMain.data.account.userName), loadSaveFile); + + NebulaModAPI.OnMultiplayerGameStarted?.Invoke(); } public override void Stop() { socket?.Stop(); + + NebulaModAPI.OnMultiplayerGameEnded?.Invoke(); } public override void Dispose() @@ -98,9 +113,9 @@ public override void SendPacketToStar(T packet, int starId) PlayerManager.SendPacketToStar(packet, starId); } - public override void SendPacketToStarExclude(T packet, int starId, NebulaConnection exclude) + public override void SendPacketToStarExclude(T packet, int starId, INebulaConnection exclude) { - PlayerManager.SendPacketToStarExcept(packet, starId, exclude); + PlayerManager.SendPacketToStarExcept(packet, starId, (NebulaConnection)exclude); } public override void Update() diff --git a/NebulaNetwork/StorageSyncManager.cs b/NebulaNetwork/StorageSyncManager.cs index 747f15b22..8e9436877 100644 --- a/NebulaNetwork/StorageSyncManager.cs +++ b/NebulaNetwork/StorageSyncManager.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Networking; using NebulaWorld; @@ -14,12 +15,12 @@ public static class StorageSyncManager public static void SendToOtherPlayersOnTheSamePlanet(NebulaConnection originator, T packet, int planetId) where T : class, new() { //Send to players on the same planet - using (Multiplayer.Session.Network.PlayerManager.GetConnectedPlayers(out var connectedPlayers)) + using (((NetworkProvider)Multiplayer.Session.Network).PlayerManager.GetConnectedPlayers(out var connectedPlayers)) { foreach (var kvp in connectedPlayers) { - NebulaConnection connection = kvp.Key; - NebulaPlayer player = kvp.Value; + NebulaConnection connection = (NebulaConnection)kvp.Key; + INebulaPlayer player = kvp.Value; if (player.Data.LocalPlanetId == planetId && connection != originator) { connection.SendPacket(packet); diff --git a/NebulaPatcher/MonoBehaviours/NebulaBootstrapper.cs b/NebulaPatcher/MonoBehaviours/NebulaBootstrapper.cs index f8511498f..adc37ea50 100644 --- a/NebulaPatcher/MonoBehaviours/NebulaBootstrapper.cs +++ b/NebulaPatcher/MonoBehaviours/NebulaBootstrapper.cs @@ -1,4 +1,5 @@ -using NebulaWorld; +using NebulaModel; +using NebulaWorld; using UnityEngine; namespace NebulaPatcher.MonoBehaviours diff --git a/NebulaPatcher/NebulaPatcher.csproj b/NebulaPatcher/NebulaPatcher.csproj index bb25bc4e6..6a85a2498 100644 --- a/NebulaPatcher/NebulaPatcher.csproj +++ b/NebulaPatcher/NebulaPatcher.csproj @@ -2,6 +2,7 @@ + diff --git a/NebulaPatcher/NebulaPlugin.cs b/NebulaPatcher/NebulaPlugin.cs index 7fc9ecc4c..def8273a5 100644 --- a/NebulaPatcher/NebulaPlugin.cs +++ b/NebulaPatcher/NebulaPlugin.cs @@ -1,5 +1,6 @@ using BepInEx; using HarmonyLib; +using NebulaAPI; using NebulaModel.Logger; using NebulaPatcher.Logger; using NebulaPatcher.MonoBehaviours; @@ -13,9 +14,8 @@ namespace NebulaPatcher { [BepInPlugin(PluginInfo.PLUGIN_ID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] - [BepInDependency("dsp.galactic-scale.2", BepInDependency.DependencyFlags.SoftDependency)] // to load after GS2 [BepInProcess("DSPGAME.exe")] - public class NebulaPlugin : BaseUnityPlugin + public class NebulaPlugin : BaseUnityPlugin, IMultiplayerMod { void Awake() { @@ -84,5 +84,11 @@ static void AddNebulaBootstrapper() Log.Info("Behaviours applied."); } + + public string Version => NebulaModel.Config.ModVersion; + public bool CheckVersion(string hostVersion, string clientVersion) + { + return hostVersion.Equals(clientVersion); + } } } diff --git a/NebulaPatcher/Patches/Dynamic/ArriveLeavePlanet_Patch.cs b/NebulaPatcher/Patches/Dynamic/ArriveLeavePlanet_Patch.cs index 8cb5761ac..f3cc7b7ed 100644 --- a/NebulaPatcher/Patches/Dynamic/ArriveLeavePlanet_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/ArriveLeavePlanet_Patch.cs @@ -14,7 +14,7 @@ public static bool ArrivePlanet_Prefix(GameData __instance, PlanetData planet) // due to that we have a time window between the vanilla ArrivePlanet() setting the localPlanet and planetId values and // our code loading the factory data. // this results in weird planet jumps, so we need to delay this until the factory data is loaded into the game. - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { // if we are the server continue with vanilla logic return true; diff --git a/NebulaPatcher/Patches/Dynamic/BuildTool_Common_Patch.cs b/NebulaPatcher/Patches/Dynamic/BuildTool_Common_Patch.cs index 564715f1a..d3648168b 100644 --- a/NebulaPatcher/Patches/Dynamic/BuildTool_Common_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/BuildTool_Common_Patch.cs @@ -1,4 +1,6 @@ using HarmonyLib; +using NebulaAPI; +using NebulaModel; using NebulaModel.Packets.Factory; using NebulaWorld; using NebulaWorld.Factory; @@ -20,6 +22,7 @@ public static bool CreatePrebuilds_Prefix(BuildTool __instance) if (!Multiplayer.IsActive) return true; + List previews = __instance.buildPreviews; if (__instance is BuildTool_BlueprintPaste) { @@ -31,13 +34,13 @@ public static bool CreatePrebuilds_Prefix(BuildTool __instance) if (Multiplayer.Session.LocalPlayer.IsHost) { int planetId = Multiplayer.Session.Factories.EventFactory?.planetId ?? GameMain.localPlanet?.id ?? -1; - Multiplayer.Session.Network.SendPacketToStar(new CreatePrebuildsRequest(planetId, previews, Multiplayer.Session.Factories.PacketAuthor == FactoryManager.AUTHOR_NONE ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor, __instance.GetType().ToString()), GameMain.galaxy.PlanetById(planetId).star.id); + Multiplayer.Session.Network.SendPacketToStar(new CreatePrebuildsRequest(planetId, previews, Multiplayer.Session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id : Multiplayer.Session.Factories.PacketAuthor, __instance.GetType().ToString()), GameMain.galaxy.PlanetById(planetId).star.id); } //If client builds, he need to first send request to the host and wait for reply - if (!Multiplayer.Session.LocalPlayer.IsHost && !Multiplayer.Session.Factories.IsIncomingRequest) + if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost && !Multiplayer.Session.Factories.IsIncomingRequest.Value) { - Multiplayer.Session.Network.SendPacket(new CreatePrebuildsRequest(GameMain.localPlanet?.id ?? -1, previews, Multiplayer.Session.Factories.PacketAuthor == FactoryManager.AUTHOR_NONE ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor, __instance.GetType().ToString())); + Multiplayer.Session.Network.SendPacket(new CreatePrebuildsRequest(GameMain.localPlanet?.id ?? -1, previews, Multiplayer.Session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id : Multiplayer.Session.Factories.PacketAuthor, __instance.GetType().ToString())); return false; } return true; @@ -50,12 +53,11 @@ public static bool CreatePrebuilds_Prefix(BuildTool __instance) [HarmonyPatch(typeof(BuildTool_BlueprintPaste), nameof(BuildTool_BlueprintPaste.CheckBuildConditions))] public static bool CheckBuildConditions(ref bool __result) { - if (Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest.Value) { __result = true; return false; } - return true; } } diff --git a/NebulaPatcher/Patches/Dynamic/CargoTraffic_Patch.cs b/NebulaPatcher/Patches/Dynamic/CargoTraffic_Patch.cs index b34ea6a35..63022de46 100644 --- a/NebulaPatcher/Patches/Dynamic/CargoTraffic_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/CargoTraffic_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel.Packets.Belt; using NebulaWorld; using NebulaWorld.Factory; @@ -32,7 +33,7 @@ public static void PickupBeltItems_Postfix() [HarmonyPatch(nameof(CargoTraffic.PutItemOnBelt))] public static void PutItemOnBelt_Prefix(int beltId, int itemId) { - if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest.Value) { Multiplayer.Session.Network.SendPacketToLocalStar(new BeltUpdatePutItemOnPacket(beltId, itemId, GameMain.data.localPlanet.id)); } @@ -43,7 +44,7 @@ public static void PutItemOnBelt_Prefix(int beltId, int itemId) public static bool AlterBeltRenderer_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -51,7 +52,7 @@ public static bool AlterBeltRenderer_Prefix() public static bool RemoveBeltRenderer_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -59,7 +60,7 @@ public static bool RemoveBeltRenderer_Prefix() public static bool AlterPathRenderer_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -67,7 +68,7 @@ public static bool AlterPathRenderer_Prefix() public static bool RemovePathRenderer_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -75,7 +76,7 @@ public static bool RemovePathRenderer_Prefix() public static bool RefreshPathUV_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } } } diff --git a/NebulaPatcher/Patches/Dynamic/DysonSphereLayer_Patch.cs b/NebulaPatcher/Patches/Dynamic/DysonSphereLayer_Patch.cs index 4e770013f..688f32b6d 100644 --- a/NebulaPatcher/Patches/Dynamic/DysonSphereLayer_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/DysonSphereLayer_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel.DataStructures; using NebulaModel.Packets.Universe; using NebulaWorld; diff --git a/NebulaPatcher/Patches/Dynamic/DysonSwarm_Patch.cs b/NebulaPatcher/Patches/Dynamic/DysonSwarm_Patch.cs index aadef5a75..81e96cec6 100644 --- a/NebulaPatcher/Patches/Dynamic/DysonSwarm_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/DysonSwarm_Patch.cs @@ -46,7 +46,7 @@ public static bool RemoveOrbit_Prefix(DysonSwarm __instance, int orbitId) public static void AddBullet_Postfix(DysonSwarm __instance, SailBullet bullet, int orbitId) { //Host is sending correction / authorization packet to correct constants of the generated bullet - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacket(new DysonSphereBulletCorrectionPacket(__instance.starData.index, bullet.id, bullet.uEndVel, bullet.uEnd)); } diff --git a/NebulaPatcher/Patches/Dynamic/EntitySignRenderer_Patch.cs b/NebulaPatcher/Patches/Dynamic/EntitySignRenderer_Patch.cs index bdaa3ce65..942c62608 100644 --- a/NebulaPatcher/Patches/Dynamic/EntitySignRenderer_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/EntitySignRenderer_Patch.cs @@ -11,7 +11,7 @@ class EntitySignRenderer_Patch [HarmonyPatch(nameof(EntitySignRenderer.Init))] public static void Init_Postfix() { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } diff --git a/NebulaPatcher/Patches/Dynamic/FactoryProductionStat_Patch.cs b/NebulaPatcher/Patches/Dynamic/FactoryProductionStat_Patch.cs index 0a3477198..c05bd37f1 100644 --- a/NebulaPatcher/Patches/Dynamic/FactoryProductionStat_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/FactoryProductionStat_Patch.cs @@ -12,7 +12,7 @@ class FactoryProductionStat_Patch public static bool GameTick_Prefix(FactoryProductionStat __instance) { //Do not run in single player for host - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } diff --git a/NebulaPatcher/Patches/Dynamic/GalacticTransport_Patch.cs b/NebulaPatcher/Patches/Dynamic/GalacticTransport_Patch.cs index dec8ef59d..2a9f92e63 100644 --- a/NebulaPatcher/Patches/Dynamic/GalacticTransport_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/GalacticTransport_Patch.cs @@ -12,7 +12,7 @@ class GalacticTransport_Patch [HarmonyPatch(nameof(GalacticTransport.SetForNewGame))] public static void SetForNewGame_Postfix() { - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacket(new ILSRequestgStationPoolSync()); } @@ -22,7 +22,7 @@ public static void SetForNewGame_Postfix() [HarmonyPatch(nameof(GalacticTransport.RemoveStationComponent))] public static bool RemoveStationComponent_Prefix(GalacticTransport __instance, int gid) { - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.Ships.PatchLockILS; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.Ships.PatchLockILS; } } } diff --git a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs index f56544510..325dea864 100644 --- a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets.Logistics; @@ -64,6 +65,8 @@ public static bool GetOrCreateFactory_Prefix(GameData __instance, PlanetFactory // Assign the factory to the result __result = __instance.factories[planet.factoryIndex]; + + NebulaModAPI.OnPlanetLoadFinished?.Invoke(planet.id); // Do not run the original method return false; @@ -103,7 +106,6 @@ public static bool OnActivePlanetFactoryLoaded_Prefix(GameData __instance, Plane { return true; } - if (planet != null) { if (GameMain.gameTick == 0L && DSPGame.SkipPrologue) @@ -135,9 +137,9 @@ public static void SetForNewGame_Postfix(GameData __instance) //Set starting star and planet to request from the server if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost) { - if (Multiplayer.Session.LocalPlayer.Data.LocalPlanetId != -1) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).Data.LocalPlanetId != -1) { - PlanetData planet = __instance.galaxy.PlanetById(Multiplayer.Session.LocalPlayer.Data.LocalPlanetId); + PlanetData planet = __instance.galaxy.PlanetById(((LocalPlayer)Multiplayer.Session.LocalPlayer).Data.LocalPlanetId); __instance.ArrivePlanet(planet); } else @@ -145,7 +147,7 @@ public static void SetForNewGame_Postfix(GameData __instance) StarData nearestStar = null; PlanetData nearestPlanet = null; //Update player's position before searching for closest star - __instance.mainPlayer.uPosition = new VectorLF3(Multiplayer.Session.LocalPlayer.Data.UPosition.x, Multiplayer.Session.LocalPlayer.Data.UPosition.y, Multiplayer.Session.LocalPlayer.Data.UPosition.z); + __instance.mainPlayer.uPosition = new VectorLF3(((LocalPlayer)Multiplayer.Session.LocalPlayer).Data.UPosition.x, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Data.UPosition.y, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Data.UPosition.z); GameMain.data.GetNearestStarPlanet(ref nearestStar, ref nearestPlanet); if (nearestStar == null) diff --git a/NebulaPatcher/Patches/Dynamic/GameHistoryData_Patch.cs b/NebulaPatcher/Patches/Dynamic/GameHistoryData_Patch.cs index 9a776c117..2de05d2ff 100644 --- a/NebulaPatcher/Patches/Dynamic/GameHistoryData_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/GameHistoryData_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaModel; using NebulaModel.Logger; using NebulaModel.Packets.GameHistory; using NebulaWorld; @@ -14,7 +15,7 @@ class GameHistoryData_Patch public static void SetForNewGame_Postfix() { // Do not run if it is not multiplayer and the player is not a client - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } @@ -100,7 +101,7 @@ public static void ResumeTechQueue_Postfix() public static bool UnlockRecipe_Prefix() { //Wait for the authoritative packet for unlocking recipes in multiplayer for clients - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.History.IsIncomingRequest; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.History.IsIncomingRequest; } [HarmonyPrefix] @@ -108,7 +109,7 @@ public static bool UnlockRecipe_Prefix() public static bool UnlockTechFunction_Prefix() { //Wait for the authoritative packet for unlocking tech features in multiplayer for clients - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.History.IsIncomingRequest; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.History.IsIncomingRequest; } [HarmonyPrefix] @@ -116,7 +117,7 @@ public static bool UnlockTechFunction_Prefix() public static bool GainTechAwards_Prefix() { //Wait for the authoritative packet for gaining tech awards in multiplayer for clients - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.History.IsIncomingRequest; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.History.IsIncomingRequest; } [HarmonyPrefix] @@ -124,7 +125,7 @@ public static bool GainTechAwards_Prefix() public static bool AddTechHash_Prefix(GameHistoryData __instance, long addcnt) { //Host in multiplayer can do normal research in the mecha - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -139,7 +140,7 @@ public static bool AddTechHash_Prefix(GameHistoryData __instance, long addcnt) public static bool DequeueTech_Prefix() { ///Wait for the authoritative packet for dequeing tech in multiplayer for clients - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.History.IsIncomingRequest; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.History.IsIncomingRequest; } [HarmonyPrefix] @@ -147,7 +148,7 @@ public static bool DequeueTech_Prefix() public static bool UnlockTech_Prefix() { //Wait for the authoritative packet for unlocking tech features in multiplayer for clients - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.History.IsIncomingRequest; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.History.IsIncomingRequest; } [HarmonyPrefix] @@ -155,7 +156,7 @@ public static bool UnlockTech_Prefix() public static void RemoveTechInQueue_Prefix(int index, out int __state) { __state = GameMain.history.techQueue[index]; - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { //we need to know which itemtypes are currently needed for refunds, so trigger refund before cancelling own research Multiplayer.Session.Network.PlayerManager.SendTechRefundPackagesToClients(__state); diff --git a/NebulaPatcher/Patches/Dynamic/GameSave_Patch.cs b/NebulaPatcher/Patches/Dynamic/GameSave_Patch.cs index a4a770c00..2d926d9a3 100644 --- a/NebulaPatcher/Patches/Dynamic/GameSave_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/GameSave_Patch.cs @@ -11,13 +11,13 @@ class GameSave_Patch [HarmonyPatch(nameof(GameSave.SaveCurrentGame))] public static bool SaveCurrentGame_Prefix(string saveName) { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { SaveManager.SaveServerData(saveName); } // Only save if in single player or if you are the host - return (!Multiplayer.IsActive && !Multiplayer.IsLeavingGame) || Multiplayer.Session.LocalPlayer.IsHost; + return (!Multiplayer.IsActive && !Multiplayer.IsLeavingGame) || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost; } [HarmonyPrefix] @@ -25,7 +25,7 @@ public static bool SaveCurrentGame_Prefix(string saveName) public static bool AutoSave_Prefix() { // Only save if in single player or if you are the host - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost; } [HarmonyPrefix] diff --git a/NebulaPatcher/Patches/Dynamic/GameScenarioLogic_Patch.cs b/NebulaPatcher/Patches/Dynamic/GameScenarioLogic_Patch.cs index eaf9e6f6c..0b5f395f4 100644 --- a/NebulaPatcher/Patches/Dynamic/GameScenarioLogic_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/GameScenarioLogic_Patch.cs @@ -14,7 +14,7 @@ public static void NotifyOnUnlockTech_Postfix(int techId) { //Synchronize unlocking techs // Do not run if it is not multiplayer and if the player is not a client - if (!Multiplayer.IsActive || !Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } diff --git a/NebulaPatcher/Patches/Dynamic/GameStatData_Patch.cs b/NebulaPatcher/Patches/Dynamic/GameStatData_Patch.cs index d5dcba399..bd822b339 100644 --- a/NebulaPatcher/Patches/Dynamic/GameStatData_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/GameStatData_Patch.cs @@ -11,7 +11,7 @@ class GameStatData_Patch [HarmonyPatch(nameof(GameStatData.AfterTick))] public static void AfterTick_Postfix() { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Statistics.CaptureStatisticalSnapshot(); } diff --git a/NebulaPatcher/Patches/Dynamic/GuideMissionStandardMode_Patch.cs b/NebulaPatcher/Patches/Dynamic/GuideMissionStandardMode_Patch.cs index c6599e58b..eb6620c30 100644 --- a/NebulaPatcher/Patches/Dynamic/GuideMissionStandardMode_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/GuideMissionStandardMode_Patch.cs @@ -11,7 +11,7 @@ class GuideMissionStandardMode_Patch public static bool Skip_Prefix() { //This prevents spawning landing capsule and preparing spawn area for the clients in multiplayer. - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost; } } } diff --git a/NebulaPatcher/Patches/Dynamic/InserterRenderer_Patch.cs b/NebulaPatcher/Patches/Dynamic/InserterRenderer_Patch.cs index b78d04271..cca039498 100644 --- a/NebulaPatcher/Patches/Dynamic/InserterRenderer_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/InserterRenderer_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaWorld; using NebulaWorld.Factory; using System; @@ -15,7 +16,7 @@ class InserterRenderer_Patch public static bool AddInst_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -23,7 +24,7 @@ public static bool AddInst_Prefix() public static bool AlterInst_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -31,7 +32,7 @@ public static bool AlterInst_Prefix() public static bool RemoveInst_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } } } diff --git a/NebulaPatcher/Patches/Dynamic/LabRenderer_Patch.cs b/NebulaPatcher/Patches/Dynamic/LabRenderer_Patch.cs index e800c47fa..d9c4c39c7 100644 --- a/NebulaPatcher/Patches/Dynamic/LabRenderer_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/LabRenderer_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaWorld; using NebulaWorld.Factory; using System; @@ -15,7 +16,7 @@ class LabRenderer_Patch public static bool AddInst_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -23,7 +24,7 @@ public static bool AddInst_Prefix() public static bool AlterInst_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -31,7 +32,7 @@ public static bool AlterInst_Prefix() public static bool RemoveInst_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } } } diff --git a/NebulaPatcher/Patches/Dynamic/Mecha_Patch.cs b/NebulaPatcher/Patches/Dynamic/Mecha_Patch.cs index 77cf16d11..16f1c7dc9 100644 --- a/NebulaPatcher/Patches/Dynamic/Mecha_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/Mecha_Patch.cs @@ -25,7 +25,7 @@ public static bool Mecha_GenerateEnergy_Prefix(Mecha __instance) // some players managed to break the fuel chamber on clients. // the game thought there is still fuel burning while not adding energy to the mecha and preventing new fuel from beeing added. // this checks for this corner case and resets the reactor energy to 0 (empty fuel chamber as displayed to the player) - if (!Multiplayer.Session.LocalPlayer.IsHost && __instance.reactorEnergy > 0 && __instance.reactorItemId == 0) + if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost && __instance.reactorEnergy > 0 && __instance.reactorItemId == 0) { __instance.reactorEnergy = 0; } @@ -38,7 +38,7 @@ public static bool Mecha_GenerateEnergy_Prefix(Mecha __instance) [HarmonyPatch(typeof(Mecha), nameof(Mecha.AddProductionStat))] public static bool AddStat_Common_Prefix() { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) return true; // TODO: Send packet to host to add stat? diff --git a/NebulaPatcher/Patches/Dynamic/ObjectRenderer_Patch.cs b/NebulaPatcher/Patches/Dynamic/ObjectRenderer_Patch.cs index 2a9ec2248..94b7ef888 100644 --- a/NebulaPatcher/Patches/Dynamic/ObjectRenderer_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/ObjectRenderer_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaWorld; using NebulaWorld.Factory; using System; @@ -15,7 +16,7 @@ class ObjectRenderer_Patch public static bool AddInst_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -23,14 +24,14 @@ public static bool AddInst_Prefix() public static bool AlterInst_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] [HarmonyPatch(nameof(ObjectRenderer.AlterInst), new Type[] { typeof(int), typeof(int), typeof(Vector3), typeof(bool) })] public static bool AlterInst_Prefix2() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } [HarmonyPrefix] @@ -38,7 +39,7 @@ public static bool AlterInst_Prefix2() public static bool RemoveInst_Prefix() { //Do not call renderer, if user is not on the planet as the request - return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == FactoryManager.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.TargetPlanet == NebulaModAPI.PLANET_NONE || GameMain.mainPlayer.planetId == Multiplayer.Session.Factories.TargetPlanet; } } } diff --git a/NebulaPatcher/Patches/Dynamic/PlanetData_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlanetData_Patch.cs index fb5727e0d..306bfc77f 100644 --- a/NebulaPatcher/Patches/Dynamic/PlanetData_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PlanetData_Patch.cs @@ -11,7 +11,7 @@ class PlanetData_Patch public static bool UnloadMeshes_Prefix(PlanetData __instance) { //Host should not unload planet meshes, since he need to permorm all terrain operations - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { //Do not unload meshes, just hide them so it is not visible UnloadVisuals(__instance); @@ -26,7 +26,7 @@ public static bool UnloadMeshes_Prefix(PlanetData __instance) public static bool UnloadData_Prefix() { //Host should not unload planet data, since he need to permorm all operations from users - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return false; } diff --git a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs index 4303d0aba..693da1925 100644 --- a/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Packets.Factory; using NebulaModel.Packets.Planet; @@ -21,9 +22,9 @@ public static void AddPrebuildData_Postfix(PlanetFactory __instance, PrebuildDat return; // If the host game called the method, we need to compute the PrebuildId ourself - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { - Multiplayer.Session.Factories.SetPrebuildRequest(__instance.planetId, __result, Multiplayer.Session.LocalPlayer.Id); + Multiplayer.Session.Factories.SetPrebuildRequest(__instance.planetId, __result, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id); } } @@ -34,7 +35,7 @@ public static bool BuildFinally_Prefix(PlanetFactory __instance, Player player, if (!Multiplayer.IsActive) return true; - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { if (!Multiplayer.Session.Factories.ContainsPrebuildRequest(__instance.planetId, prebuildId)) { @@ -48,17 +49,17 @@ public static bool BuildFinally_Prefix(PlanetFactory __instance, Player player, Multiplayer.Session.Factories.RemovePrebuildRequest(__instance.planetId, prebuildId); } - if (Multiplayer.Session.LocalPlayer.IsHost || !Multiplayer.Session.Factories.IsIncomingRequest) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || !Multiplayer.Session.Factories.IsIncomingRequest.Value) { - Multiplayer.Session.Network.SendPacket(new BuildEntityRequest(__instance.planetId, prebuildId, Multiplayer.Session.Factories.PacketAuthor == FactoryManager.AUTHOR_NONE ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor)); + Multiplayer.Session.Network.SendPacket(new BuildEntityRequest(__instance.planetId, prebuildId, Multiplayer.Session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id : Multiplayer.Session.Factories.PacketAuthor)); } - if (!Multiplayer.Session.LocalPlayer.IsHost && !Multiplayer.Session.Factories.IsIncomingRequest && !Multiplayer.Session.Drones.IsPendingBuildRequest(-prebuildId)) + if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost && !Multiplayer.Session.Factories.IsIncomingRequest.Value && !Multiplayer.Session.Drones.IsPendingBuildRequest(-prebuildId)) { Multiplayer.Session.Drones.AddBuildRequestSent(-prebuildId); } - return Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.Factories.IsIncomingRequest; + return ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.Factories.IsIncomingRequest.Value; } [HarmonyPrefix] @@ -68,12 +69,12 @@ public static bool UpgradeFinally_Prefix(PlanetFactory __instance, Player player if (!Multiplayer.IsActive) return true; - if (Multiplayer.Session.LocalPlayer.IsHost || !Multiplayer.Session.Factories.IsIncomingRequest) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || !Multiplayer.Session.Factories.IsIncomingRequest.Value) { - Multiplayer.Session.Network.SendPacket(new UpgradeEntityRequest(__instance.planetId, objId, replace_item_proto.ID, Multiplayer.Session.Factories.PacketAuthor == -1 ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor)); + Multiplayer.Session.Network.SendPacket(new UpgradeEntityRequest(__instance.planetId, objId, replace_item_proto.ID, Multiplayer.Session.Factories.PacketAuthor == -1 ? ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id : Multiplayer.Session.Factories.PacketAuthor)); } - return Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.Factories.IsIncomingRequest; + return ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.Factories.IsIncomingRequest.Value; } [HarmonyPrefix] @@ -101,7 +102,7 @@ public static void InternalUpdate_Postfix() [HarmonyPatch(nameof(PlanetFactory.PasteBuildingSetting))] public static void PasteBuildingSetting_Prefix(PlanetFactory __instance, int objectId) { - if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest.Value) { Multiplayer.Session.Network.SendPacketToLocalStar(new PasteBuildingSettingUpdate(objectId, BuildingParameters.clipboard, GameMain.localPlanet?.id ?? -1)); } @@ -111,7 +112,7 @@ public static void PasteBuildingSetting_Prefix(PlanetFactory __instance, int obj [HarmonyPatch(nameof(PlanetFactory.FlattenTerrainReform))] public static void FlattenTerrainReform_Prefix(PlanetFactory __instance, Vector3 center, float radius, int reformSize, bool veinBuried, float fade0) { - if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest.Value) { Multiplayer.Session.Network.SendPacketToLocalStar(new FoundationBuildUpdatePacket(radius, reformSize, veinBuried, fade0)); } @@ -133,7 +134,7 @@ public static void RemoveVeinWithComponents_Postfix(PlanetFactory __instance, in { if (Multiplayer.IsActive && !Multiplayer.Session.Planets.IsIncomingRequest) { - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacketToStar(new VegeMinedPacket(__instance.planetId, id, 0, true), __instance.planet.star.id); } diff --git a/NebulaPatcher/Patches/Dynamic/PlanetModelingManager_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlanetModelingManager_Patch.cs index 8c457133a..af906d519 100644 --- a/NebulaPatcher/Patches/Dynamic/PlanetModelingManager_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PlanetModelingManager_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Packets.Planet; using NebulaModel.Packets.Universe; @@ -16,7 +17,7 @@ public class PlanetModelingManager_Patch public static bool RequestLoadPlanetFactory_Prefix(PlanetData planet) { // Run the original method if this is the master client or in single player games - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -41,6 +42,8 @@ public static bool RequestLoadPlanetFactory_Prefix(PlanetData planet) // Request factory Log.Info($"Requested factory for planet {planet.name} (ID: {planet.id}) from host"); Multiplayer.Session.Network.SendPacket(new FactoryLoadRequest(planet.id)); + + NebulaModAPI.OnPlanetLoadRequest?.Invoke(planet.id); // Skip running the actual method return false; @@ -54,7 +57,7 @@ public static bool RequestLoadPlanet_Prefix(PlanetData planet) // RequestLoadStar takes care of these instead currently // Run the original method if this is the master client or in single player games - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -69,7 +72,7 @@ public static bool RequestLoadPlanet_Prefix(PlanetData planet) public static bool RequestLoadStar_Prefix(StarData star) { // Run the original method if this is the master client or in single player games - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -82,6 +85,9 @@ public static bool RequestLoadStar_Prefix(StarData star) Log.Info($"Requesting DysonSphere for system {star.displayName} (Index: {star.index})"); Multiplayer.Session.Network.SendPacket(new DysonSphereLoadRequest(star.index)); } + + NebulaModAPI.OnStarLoadRequest?.Invoke(star.index); + return false; } diff --git a/NebulaPatcher/Patches/Dynamic/PlanetTransport_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlanetTransport_Patch.cs index a9d04db7d..d1757e1b8 100644 --- a/NebulaPatcher/Patches/Dynamic/PlanetTransport_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PlanetTransport_Patch.cs @@ -23,7 +23,7 @@ public static bool SetStationStorage_Postfix(PlanetTransport __instance, int sta Multiplayer.Session.Network.SendPacket(packet); } - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -53,7 +53,7 @@ public static void NewStationComponent_AddPlanetId_Postfix(PlanetTransport __ins [HarmonyPatch(nameof(PlanetTransport.NewStationComponent))] public static void NewStationComponent_BroadcastNewILS_Postfix(PlanetTransport __instance, StationComponent __result, int _entityId, int _pcId, PrefabDesc _desc) { - if (!Multiplayer.IsActive || !Multiplayer.Session.LocalPlayer.IsHost) return; + if (!Multiplayer.IsActive || !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) return; // We don't need to do this for PLS if (__result.gid == 0) return; @@ -92,7 +92,7 @@ public static void Import_Postfix(PlanetTransport __instance) [HarmonyPatch(nameof(PlanetTransport.RemoveStationComponent))] public static bool RemoveStationComponent_Prefix(PlanetTransport __instance, int id) { - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.Ships.PatchLockILS; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.Ships.PatchLockILS; } /* @@ -102,7 +102,7 @@ public static bool RemoveStationComponent_Prefix(PlanetTransport __instance, int [HarmonyPatch(nameof(PlanetTransport.RemoveStationComponent))] public static void RemoveStationComponent_Postfix(PlanetTransport __instance, int id) { - if (!Multiplayer.IsActive || !Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } diff --git a/NebulaPatcher/Patches/Dynamic/PlayerAction_Build_Patch.cs b/NebulaPatcher/Patches/Dynamic/PlayerAction_Build_Patch.cs index 3155fa5a4..5d78c7abb 100644 --- a/NebulaPatcher/Patches/Dynamic/PlayerAction_Build_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PlayerAction_Build_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel.Logger; using NebulaModel.Packets.Factory; using NebulaWorld; @@ -18,11 +19,11 @@ public static bool DoDismantleObject_Prefix(PlayerAction_Build __instance, int o return true; } - int planetId = Multiplayer.Session.Factories.TargetPlanet != FactoryManager.PLANET_NONE ? Multiplayer.Session.Factories.TargetPlanet : __instance.planet?.id ?? -1; + int planetId = Multiplayer.Session.Factories.TargetPlanet != NebulaModAPI.PLANET_NONE ? Multiplayer.Session.Factories.TargetPlanet : __instance.planet?.id ?? -1; // TODO: handle if 2 clients or if host and client trigger a destruct of the same object at the same time // If the object is a prebuild, remove it from the prebuild request list - if (Multiplayer.Session.LocalPlayer.IsHost && objId < 0) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost && objId < 0) { if (!Multiplayer.Session.Factories.ContainsPrebuildRequest(planetId, -objId)) { @@ -34,12 +35,12 @@ public static bool DoDismantleObject_Prefix(PlayerAction_Build __instance, int o } - if (Multiplayer.Session.LocalPlayer.IsHost || !Multiplayer.Session.Factories.IsIncomingRequest) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || !Multiplayer.Session.Factories.IsIncomingRequest.Value) { - Multiplayer.Session.Network.SendPacket(new DestructEntityRequest(planetId, objId, Multiplayer.Session.Factories.PacketAuthor == FactoryManager.AUTHOR_NONE ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor)); + Multiplayer.Session.Network.SendPacket(new DestructEntityRequest(planetId, objId, Multiplayer.Session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id : Multiplayer.Session.Factories.PacketAuthor)); } - return Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.Factories.IsIncomingRequest; + return ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.Factories.IsIncomingRequest.Value; } [HarmonyPrefix] @@ -51,7 +52,7 @@ public static bool SetFactoryReferences_Prefix() return true; } - if (Multiplayer.Session.Factories.IsIncomingRequest && Multiplayer.Session.Factories.PacketAuthor != Multiplayer.Session.LocalPlayer.Id && Multiplayer.Session.Factories.TargetPlanet != GameMain.localPlanet?.id) + if (Multiplayer.Session.Factories.IsIncomingRequest.Value && Multiplayer.Session.Factories.PacketAuthor != ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id && Multiplayer.Session.Factories.TargetPlanet != GameMain.localPlanet?.id) { return false; } diff --git a/NebulaPatcher/Patches/Dynamic/Player_Patch.cs b/NebulaPatcher/Patches/Dynamic/Player_Patch.cs index b614ea36d..3351e4273 100644 --- a/NebulaPatcher/Patches/Dynamic/Player_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/Player_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaWorld; using NebulaWorld.Factory; @@ -12,7 +13,7 @@ class Player_Patch public static bool RemoveLayer_Prefix() { //Soil should be given in singleplayer or to the player who is author of the "Build" request, or to the host if there is no author. - return !Multiplayer.IsActive || Multiplayer.Session.Factories.PacketAuthor == Multiplayer.Session.LocalPlayer.Id || (Multiplayer.Session.LocalPlayer.IsHost && Multiplayer.Session.Factories.PacketAuthor == FactoryManager.AUTHOR_NONE) || !Multiplayer.Session.Factories.IsIncomingRequest; + return !Multiplayer.IsActive || Multiplayer.Session.Factories.PacketAuthor == ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id || (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost && Multiplayer.Session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE) || !Multiplayer.Session.Factories.IsIncomingRequest.Value; } [HarmonyPrefix] @@ -25,7 +26,7 @@ public static bool TryAddItemToPackage_Prefix(ref int __result) } // We should only add items to player if player requested - if (Multiplayer.Session.Factories.IsIncomingRequest && Multiplayer.Session.Factories.PacketAuthor != Multiplayer.Session.LocalPlayer.Id) + if (Multiplayer.Session.Factories.IsIncomingRequest.Value && Multiplayer.Session.Factories.PacketAuthor != ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id) { __result = 0; return false; @@ -45,7 +46,7 @@ public static bool UseHandItems_Prefix(ref int __result) } // We should only take items to player if player requested - if (Multiplayer.Session.Factories.IsIncomingRequest && Multiplayer.Session.Factories.PacketAuthor != Multiplayer.Session.LocalPlayer.Id) + if (Multiplayer.Session.Factories.IsIncomingRequest.Value && Multiplayer.Session.Factories.PacketAuthor != ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id) { __result = 1; return false; diff --git a/NebulaPatcher/Patches/Dynamic/PostEffectController_Patch.cs b/NebulaPatcher/Patches/Dynamic/PostEffectController_Patch.cs index 0f292247e..a6cee6fed 100644 --- a/NebulaPatcher/Patches/Dynamic/PostEffectController_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PostEffectController_Patch.cs @@ -11,7 +11,7 @@ class PostEffectController_Patch [HarmonyPatch(nameof(PostEffectController.Start))] public static void Start_Postfix() { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } diff --git a/NebulaPatcher/Patches/Dynamic/PowerSystemRenderer_Patch.cs b/NebulaPatcher/Patches/Dynamic/PowerSystemRenderer_Patch.cs index 468e7192c..be9496fbb 100644 --- a/NebulaPatcher/Patches/Dynamic/PowerSystemRenderer_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/PowerSystemRenderer_Patch.cs @@ -11,7 +11,7 @@ class PowerSystemRenderer_Patch [HarmonyPatch(nameof(PowerSystemRenderer.Init))] public static void Init_Postfix() { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } diff --git a/NebulaPatcher/Patches/Dynamic/ProductionStatistics_Patch.cs b/NebulaPatcher/Patches/Dynamic/ProductionStatistics_Patch.cs index 23d618388..2a7ced4e2 100644 --- a/NebulaPatcher/Patches/Dynamic/ProductionStatistics_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/ProductionStatistics_Patch.cs @@ -10,7 +10,7 @@ class ProductionStatistics_Patch [HarmonyPatch(nameof(ProductionStatistics.PrepareTick))] public static bool PrepareTick_Prefix(ProductionStatistics __instance) { - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { for (int i = 0; i < __instance.gameData.factoryCount; i++) { @@ -28,7 +28,7 @@ public static bool PrepareTick_Prefix(ProductionStatistics __instance) [HarmonyPatch(nameof(ProductionStatistics.AfterTick))] public static bool AfterTick_Prefix(ProductionStatistics __instance) { - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { for (int i = 0; i < __instance.gameData.factoryCount; i++) { @@ -43,7 +43,7 @@ public static bool AfterTick_Prefix(ProductionStatistics __instance) [HarmonyPatch(nameof(ProductionStatistics.GameTick))] public static bool GameTick_Prefix(ProductionStatistics __instance) { - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { //Do not run on client if you do not have all data for (int i = 0; i < __instance.gameData.factoryCount; i++) diff --git a/NebulaPatcher/Patches/Dynamic/StationComponent_Patch.cs b/NebulaPatcher/Patches/Dynamic/StationComponent_Patch.cs index 0b1ade8b0..f8905ee09 100644 --- a/NebulaPatcher/Patches/Dynamic/StationComponent_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/StationComponent_Patch.cs @@ -13,7 +13,7 @@ class StationComponent_Patch [HarmonyPatch(nameof(StationComponent.InternalTickRemote))] public static bool InternalTickRemote_Prefix(StationComponent __instance, int timeGene, double dt, float shipSailSpeed, float shipWarpSpeed, int shipCarries, StationComponent[] gStationPool, AstroPose[] astroPoses, VectorLF3 relativePos, Quaternion relativeRot, bool starmap, int[] consumeRegister) { - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { // skip vanilla code entirely and use our modified version instead (which focuses on ship movement) // call our InternalTickRemote() for every StationComponent in game. Normally this would be done by each PlanetFactory, but as a client @@ -29,7 +29,7 @@ public static bool InternalTickRemote_Prefix(StationComponent __instance, int ti [HarmonyPatch(nameof(StationComponent.RematchRemotePairs))] public static bool RematchRemotePairs_Prefix(StationComponent __instance, StationComponent[] gStationPool, int gStationCursor, int keyStationGId, int shipCarries) { - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { // skip vanilla code entirely for clients as we do this event based triggered by the server return false; @@ -42,7 +42,7 @@ public static bool RematchRemotePairs_Prefix(StationComponent __instance, Statio [HarmonyPatch(nameof(StationComponent.RematchRemotePairs))] public static void RematchRemotePairs_Postfix(StationComponent __instance) { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost && __instance.isStellar) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost && __instance.isStellar) { int[] shipIndex = new int[__instance.workShipDatas.Length]; int[] otherGId = new int[__instance.workShipDatas.Length]; @@ -63,7 +63,7 @@ public static void RematchRemotePairs_Postfix(StationComponent __instance) [HarmonyPatch(nameof(StationComponent.IdleShipGetToWork))] public static void IdleShipGetToWork_Postfix(StationComponent __instance, int index) { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { ILSShipData packet = new ILSShipData(true, __instance.workShipDatas[__instance.workShipCount - 1].planetA, __instance.workShipDatas[__instance.workShipCount - 1].planetB, __instance.workShipDatas[__instance.workShipCount - 1].itemId, __instance.workShipDatas[__instance.workShipCount - 1].itemCount, __instance.gid, __instance.workShipDatas[__instance.workShipCount - 1].otherGId, index, __instance.workShipDatas[__instance.workShipCount - 1].warperCnt, __instance.warperCount); Multiplayer.Session.Network.SendPacket(packet); @@ -74,7 +74,7 @@ public static void IdleShipGetToWork_Postfix(StationComponent __instance, int in [HarmonyPatch(nameof(StationComponent.WorkShipBackToIdle))] public static void WorkShipBackToIdle_Postfix(StationComponent __instance, int index) { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { ILSShipData packet = new ILSShipData(false, __instance.gid, index); Multiplayer.Session.Network.SendPacket(packet); diff --git a/NebulaPatcher/Patches/Dynamic/StorageComponent_Patch.cs b/NebulaPatcher/Patches/Dynamic/StorageComponent_Patch.cs index fd7a0ac9c..b2e601a0b 100644 --- a/NebulaPatcher/Patches/Dynamic/StorageComponent_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/StorageComponent_Patch.cs @@ -78,7 +78,7 @@ public static bool TakeTailItems_Prefix(StorageComponent __instance, ref int cou } // We should only take items to player if player requested - if (Multiplayer.Session.Factories.IsIncomingRequest && Multiplayer.Session.Factories.PacketAuthor != Multiplayer.Session.LocalPlayer.Id) + if (Multiplayer.Session.Factories.IsIncomingRequest.Value && Multiplayer.Session.Factories.PacketAuthor != ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id) { count = 1; return false; @@ -95,7 +95,7 @@ public static bool TakeTailItems_Prefix(StorageComponent __instance, ref int cou return; } - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { StorageSyncManager.SendToPlayersOnTheSamePlanet(packet, GameMain.data.localPlanet.id); } diff --git a/NebulaPatcher/Patches/Dynamic/TrashContainer_Patch.cs b/NebulaPatcher/Patches/Dynamic/TrashContainer_Patch.cs index 1320ca52b..d137696d2 100644 --- a/NebulaPatcher/Patches/Dynamic/TrashContainer_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/TrashContainer_Patch.cs @@ -28,7 +28,7 @@ public static void NewTrash_Postfix(int __result, TrashObject trashObj, TrashDat { //Refresh trash to assign local planet Id and local position GameMain.data.trashSystem.Gravity(ref trashData, GameMain.data.galaxy.astroPoses, 0, 0, 0, (GameMain.data.localPlanet != null) ? GameMain.data.localPlanet.id : 0, (GameMain.data.localPlanet != null) ? GameMain.data.localPlanet.data : null); - Multiplayer.Session.Network.SendPacket(new TrashSystemNewTrashCreatedPacket(__result, trashObj, trashData, Multiplayer.Session.LocalPlayer.Id, GameMain.mainPlayer.planetId)); + Multiplayer.Session.Network.SendPacket(new TrashSystemNewTrashCreatedPacket(__result, trashObj, trashData, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id, GameMain.mainPlayer.planetId)); } } } diff --git a/NebulaPatcher/Patches/Dynamic/TrashSystem_Patch.cs b/NebulaPatcher/Patches/Dynamic/TrashSystem_Patch.cs index b916acc0a..f0168a11a 100644 --- a/NebulaPatcher/Patches/Dynamic/TrashSystem_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/TrashSystem_Patch.cs @@ -13,7 +13,7 @@ class TrashSystem_Patch public static void SetForNewGame_Postfix() { //Request trash data from the host - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacket(new TrashSystemRequestDataPacket(GameMain.localStar == null ? -1 : GameMain.localStar.id)); } diff --git a/NebulaPatcher/Patches/Dynamic/UIAutoSave_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIAutoSave_Patch.cs index c05806bb4..dd7806065 100644 --- a/NebulaPatcher/Patches/Dynamic/UIAutoSave_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIAutoSave_Patch.cs @@ -16,7 +16,7 @@ public static void _OnOpen_Postfix(UIAutoSave __instance) // Hide AutoSave failed message on clients, since client cannot save in multiplayer CanvasGroup contentCanvas = __instance.contentCanvas; if (contentCanvas == null) return; - contentCanvas.gameObject.SetActive(!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost); + contentCanvas.gameObject.SetActive(!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost); Log.Warn($"UIAutoSave active: {contentCanvas.gameObject.activeSelf}"); } @@ -25,7 +25,7 @@ public static void _OnOpen_Postfix(UIAutoSave __instance) [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")] public static bool _OnLateUpdate_Prefix() { - return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost; + return !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost; } } } diff --git a/NebulaPatcher/Patches/Dynamic/UIEscMenu_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIEscMenu_Patch.cs index 544a205b9..e58070ec5 100644 --- a/NebulaPatcher/Patches/Dynamic/UIEscMenu_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIEscMenu_Patch.cs @@ -15,7 +15,7 @@ public static void _OnOpen_Prefix(UIEscMenu __instance) { // Disable save game button if you are a client in a multiplayer session Button saveGameWindowButton = __instance.button2; - SetButtonEnableState(saveGameWindowButton, !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost); + SetButtonEnableState(saveGameWindowButton, !Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost); // Disable load game button if in a multiplayer session Button loadGameWindowButton = __instance.button3; diff --git a/NebulaPatcher/Patches/Dynamic/UIGameMenu_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIGameMenu_Patch.cs index eed090a7e..7b35b4bf9 100644 --- a/NebulaPatcher/Patches/Dynamic/UIGameMenu_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIGameMenu_Patch.cs @@ -11,7 +11,7 @@ class UIGameMenu_Patch [HarmonyPatch(nameof(UIGameMenu.OnDfGuideButtonClick))] public static void OnDfGuideButtonClick_Postfix(UIGameMenu __instance) { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } @@ -24,7 +24,7 @@ public static void OnDfGuideButtonClick_Postfix(UIGameMenu __instance) [HarmonyPatch(nameof(UIGameMenu.OnDfIconButtonClick))] public static void OnDfIconButtonClick_Postfix() { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } @@ -37,7 +37,7 @@ public static void OnDfIconButtonClick_Postfix() [HarmonyPatch(nameof(UIGameMenu.OnDfLightButtonClick))] public static void OnDfLightButtonClick_Postfix() { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } @@ -50,7 +50,7 @@ public static void OnDfLightButtonClick_Postfix() [HarmonyPatch(nameof(UIGameMenu.OnDfPowerButtonClick))] public static void OnDfPowerButtonClick_Postfix() { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } @@ -63,7 +63,7 @@ public static void OnDfPowerButtonClick_Postfix() [HarmonyPatch(nameof(UIGameMenu.OnDfSignButtonClick))] public static void OnDfSignButtonClick_Postfix() { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } @@ -76,7 +76,7 @@ public static void OnDfSignButtonClick_Postfix() [HarmonyPatch(nameof(UIGameMenu.OnDfVeinButtonClick))] public static void OnDfVeinButtonClick_Postfix(UIGameMenu __instance) { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } diff --git a/NebulaPatcher/Patches/Dynamic/UIGame_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIGame_Patch.cs index 1b630e5b8..c89317ac4 100644 --- a/NebulaPatcher/Patches/Dynamic/UIGame_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIGame_Patch.cs @@ -12,7 +12,7 @@ class UIGame_Patch [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")] public static void _OnInit_Postfix(UIGame __instance) { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } diff --git a/NebulaPatcher/Patches/Dynamic/UIOptionWindow_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIOptionWindow_Patch.cs index d4ef6f4e8..da35422c0 100644 --- a/NebulaPatcher/Patches/Dynamic/UIOptionWindow_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIOptionWindow_Patch.cs @@ -1,5 +1,6 @@ using HarmonyLib; using NebulaModel; +using NebulaAPI; using NebulaModel.Attributes; using NebulaModel.Logger; using NGPT; @@ -45,7 +46,7 @@ public static void _OnCreate_Postfix(UIOptionWindow __instance) float tabOffset = lastTab.anchoredPosition.x - beforeLastTab.anchoredPosition.x; multiplayerTab = Object.Instantiate(lastTab, lastTab.parent, true); multiplayerTab.anchoredPosition = new Vector2(lastTab.anchoredPosition.x + tabOffset, lastTab.anchoredPosition.y); - UIButton[] newTabButtons = CollectionExtensions.AddToArray(tabButtons, multiplayerTab.GetComponent()); + UIButton[] newTabButtons = tabButtons.AddToArray(multiplayerTab.GetComponent()); __instance.tabButtons = newTabButtons; // Update multiplayer tab text @@ -53,7 +54,7 @@ public static void _OnCreate_Postfix(UIOptionWindow __instance) tabText.GetComponent().enabled = false; tabText.text = "Multiplayer"; Text[] tabTexts = __instance.tabTexts; - Text[] newTabTexts = CollectionExtensions.AddToArray(tabTexts, tabText); + Text[] newTabTexts = tabTexts.AddToArray(tabText); __instance.tabTexts = newTabTexts; // Add multiplayer tab content @@ -62,11 +63,11 @@ public static void _OnCreate_Postfix(UIOptionWindow __instance) multiplayerContent = Object.Instantiate(contentTemplate, contentTemplate.parent, true); multiplayerContent.name = "multiplayer-content"; - Tweener[] newContents = CollectionExtensions.AddToArray(tabTweeners, multiplayerContent.GetComponent()); + Tweener[] newContents = tabTweeners.AddToArray(multiplayerContent.GetComponent()); __instance.tabTweeners = newContents; UIButton[] revertButtons = __instance.revertButtons; RectTransform revertButton = multiplayerContent.Find("revert-button").GetComponent(); - UIButton[] newRevertButtons = CollectionExtensions.AddToArray(revertButtons, revertButton.GetComponent()); + UIButton[] newRevertButtons = revertButtons.AddToArray(revertButton.GetComponent()); __instance.revertButtons = newRevertButtons; // Remove unwanted GameObject diff --git a/NebulaPatcher/Patches/Dynamic/UIPlanetDetail_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIPlanetDetail_Patch.cs index cbcae27ec..a4dae5676 100644 --- a/NebulaPatcher/Patches/Dynamic/UIPlanetDetail_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIPlanetDetail_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel.Packets.Universe; using NebulaWorld; using NebulaWorld.Factory; @@ -12,12 +13,12 @@ class UIPlanetDetail_Patch [HarmonyPatch(nameof(UIPlanetDetail.OnNameInputEndEdit))] public static void OnNameInputEndEdit_Postfix(UIPlanetDetail __instance) { - if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest.Value) { if (__instance.planet != null && !string.IsNullOrEmpty(__instance.planet.overrideName)) { // Send packet with new planet name - Multiplayer.Session.Network.SendPacket(new NameInputPacket(__instance.planet.overrideName, FactoryManager.STAR_NONE, __instance.planet.id, Multiplayer.Session.LocalPlayer.Id)); + Multiplayer.Session.Network.SendPacket(new NameInputPacket(__instance.planet.overrideName, NebulaModAPI.STAR_NONE, __instance.planet.id, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id)); } } } diff --git a/NebulaPatcher/Patches/Dynamic/UIPlanetGlobe_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIPlanetGlobe_Patch.cs index a6579ee56..d755393b2 100644 --- a/NebulaPatcher/Patches/Dynamic/UIPlanetGlobe_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIPlanetGlobe_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel.Packets.Universe; using NebulaWorld; using NebulaWorld.Factory; @@ -12,17 +13,17 @@ class UIPlanetGlobe_Patch [HarmonyPatch(nameof(UIPlanetGlobe.OnNameInputEndEdit))] public static void OnNameInputEndEdit_Postfix() { - if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest.Value) { if (GameMain.localPlanet != null && !string.IsNullOrEmpty(GameMain.localPlanet.overrideName)) { // Send packet with new planet name - Multiplayer.Session.Network.SendPacket(new NameInputPacket(GameMain.localPlanet.overrideName, FactoryManager.STAR_NONE, GameMain.localPlanet.id, Multiplayer.Session.LocalPlayer.Id)); + Multiplayer.Session.Network.SendPacket(new NameInputPacket(GameMain.localPlanet.overrideName, NebulaModAPI.STAR_NONE, GameMain.localPlanet.id, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id)); } else if (GameMain.localStar != null && !string.IsNullOrEmpty(GameMain.localStar.overrideName)) { // Send packet with new star name - Multiplayer.Session.Network.SendPacket(new NameInputPacket(GameMain.localStar.overrideName, GameMain.localStar.id, FactoryManager.PLANET_NONE, Multiplayer.Session.LocalPlayer.Id)); + Multiplayer.Session.Network.SendPacket(new NameInputPacket(GameMain.localStar.overrideName, GameMain.localStar.id, NebulaModAPI.PLANET_NONE, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id)); } } } diff --git a/NebulaPatcher/Patches/Dynamic/UIRealtimeTip_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIRealtimeTip_Patch.cs index bccb2c774..9a561e108 100644 --- a/NebulaPatcher/Patches/Dynamic/UIRealtimeTip_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIRealtimeTip_Patch.cs @@ -14,7 +14,7 @@ class UIRealtimeTip_Patch public static bool Popup_Prefix() { //Do not show popups if they are triggered remotely - return !Multiplayer.IsActive || (!Multiplayer.Session.Factories.IsIncomingRequest); + return !Multiplayer.IsActive || !Multiplayer.Session.Factories.IsIncomingRequest.Value; } [HarmonyPrefix] @@ -22,7 +22,7 @@ public static bool Popup_Prefix() public static bool Popup_Prefix2() { //Do not show popups if they are triggered remotely - return !Multiplayer.IsActive || (!Multiplayer.Session.Factories.IsIncomingRequest); + return !Multiplayer.IsActive || !Multiplayer.Session.Factories.IsIncomingRequest.Value; } [HarmonyPrefix] @@ -30,7 +30,7 @@ public static bool Popup_Prefix2() public static bool Popup_Prefix3() { //Do not show popups if they are triggered remotely - return !Multiplayer.IsActive || (!Multiplayer.Session.Factories.IsIncomingRequest); + return !Multiplayer.IsActive || !Multiplayer.Session.Factories.IsIncomingRequest.Value; } } } diff --git a/NebulaPatcher/Patches/Dynamic/UIStarDetail_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIStarDetail_Patch.cs index 8f0e6af8b..b38d19638 100644 --- a/NebulaPatcher/Patches/Dynamic/UIStarDetail_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIStarDetail_Patch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NebulaAPI; using NebulaModel.Packets.Universe; using NebulaWorld; using NebulaWorld.Factory; @@ -12,12 +13,12 @@ class UIStarDetail_Patch [HarmonyPatch(nameof(UIStarDetail.OnNameInputEndEdit))] public static void OnNameInputEndEdit_Postfix(UIStarDetail __instance) { - if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest.Value) { if (__instance.star != null && !string.IsNullOrEmpty(__instance.star.overrideName)) { // Send packet with new star name - Multiplayer.Session.Network.SendPacket(new NameInputPacket(__instance.star.overrideName, __instance.star.id, FactoryManager.PLANET_NONE, Multiplayer.Session.LocalPlayer.Id)); + Multiplayer.Session.Network.SendPacket(new NameInputPacket(__instance.star.overrideName, __instance.star.id, NebulaModAPI.PLANET_NONE, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id)); } } } diff --git a/NebulaPatcher/Patches/Dynamic/UIStationStorage_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIStationStorage_Patch.cs index b2eec3d3a..872a02133 100644 --- a/NebulaPatcher/Patches/Dynamic/UIStationStorage_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIStationStorage_Patch.cs @@ -22,7 +22,7 @@ public static bool OnItemIconMouseDown_Postfix(UIStationStorage __instance, Base Multiplayer.Session.StationsUI.LastMouseEvent = evt; Multiplayer.Session.StationsUI.LastMouseEventWasDown = true; StationUI packet; - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { PointerEventData pointEventData = evt as PointerEventData; if (GameMain.mainPlayer.inhandItemId == __instance.station.storage[__instance.index].itemId && pointEventData.button == PointerEventData.InputButton.Left) @@ -42,7 +42,7 @@ public static bool OnItemIconMouseDown_Postfix(UIStationStorage __instance, Base packet = new StationUI(__instance.stationWindow.factory.planet.id, __instance.station.id, __instance.station.gid, __instance.index, StationUI.EUISettings.AddOrRemoveItemFromStorageRequest, __instance.station.storage[__instance.index].itemId, __instance.station.storage[__instance.index].count); Multiplayer.Session.Network.SendPacket(packet); } - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -64,7 +64,7 @@ public static bool OnItemIconMouseUp_Postfix(UIStationStorage __instance, BaseEv Multiplayer.Session.StationsUI.LastMouseEvent = evt; Multiplayer.Session.StationsUI.LastMouseEventWasDown = false; StationUI packet; - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { if (__instance.insplit) { @@ -79,7 +79,7 @@ public static bool OnItemIconMouseUp_Postfix(UIStationStorage __instance, BaseEv packet = new StationUI(__instance.stationWindow.factory.planet.id, __instance.station.id, __instance.station.gid, __instance.index, StationUI.EUISettings.AddOrRemoveItemFromStorageRequest, __instance.station.storage[__instance.index].itemId, __instance.station.storage[__instance.index].count); Multiplayer.Session.Network.SendPacket(packet); } - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } diff --git a/NebulaPatcher/Patches/Dynamic/UIStationWindow_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIStationWindow_Patch.cs index 7ffcd3336..2e81aadf8 100644 --- a/NebulaPatcher/Patches/Dynamic/UIStationWindow_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIStationWindow_Patch.cs @@ -18,7 +18,7 @@ public static bool OnMaxChargePowerSliderValueChange_Prefix(UIStationWindow __in { StationUI packet = new StationUI(__instance.factory.planet.id, __instance.factory.transport.stationPool[__instance.stationId].id, __instance.factory.transport.stationPool[__instance.stationId].gid, StationUI.EUISettings.MaxChargePower, value); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -31,11 +31,11 @@ public static bool OnMaxChargePowerSliderValueChange_Prefix(UIStationWindow __in [HarmonyPatch(nameof(UIStationWindow.OnMaxTripDroneSliderValueChange))] public static bool OnMaxTripDroneSliderValueChange_Prefix(UIStationWindow __instance, float value) { - if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || Multiplayer.Session.LocalPlayer.IsHost)) + if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost)) { StationUI packet = new StationUI(__instance.factory.planet.id, __instance.factory.transport.stationPool[__instance.stationId].id, __instance.factory.transport.stationPool[__instance.stationId].gid, StationUI.EUISettings.MaxTripDrones, value); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -48,11 +48,11 @@ public static bool OnMaxTripDroneSliderValueChange_Prefix(UIStationWindow __inst [HarmonyPatch(nameof(UIStationWindow.OnMaxTripVesselSliderValueChange))] public static bool OnMaxTripVesselSliderValueChange_Prefix(UIStationWindow __instance, float value) { - if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || Multiplayer.Session.LocalPlayer.IsHost)) + if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost)) { StationUI packet = new StationUI(__instance.factory.planet.id, __instance.factory.transport.stationPool[__instance.stationId].id, __instance.factory.transport.stationPool[__instance.stationId].gid, StationUI.EUISettings.MaxTripVessel, value); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -65,11 +65,11 @@ public static bool OnMaxTripVesselSliderValueChange_Prefix(UIStationWindow __ins [HarmonyPatch(nameof(UIStationWindow.OnMinDeliverDroneValueChange))] public static bool OnMinDeliverDroneValueChange_Prefix(UIStationWindow __instance, float value) { - if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || Multiplayer.Session.LocalPlayer.IsHost)) + if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost)) { StationUI packet = new StationUI(__instance.factory.planet.id, __instance.factory.transport.stationPool[__instance.stationId].id, __instance.factory.transport.stationPool[__instance.stationId].gid, StationUI.EUISettings.MinDeliverDrone, value); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -82,11 +82,11 @@ public static bool OnMinDeliverDroneValueChange_Prefix(UIStationWindow __instanc [HarmonyPatch(nameof(UIStationWindow.OnMinDeliverVesselValueChange))] public static bool OnMinDeliverVesselValueChange_Prefix(UIStationWindow __instance, float value) { - if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || Multiplayer.Session.LocalPlayer.IsHost)) + if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost)) { StationUI packet = new StationUI(__instance.factory.planet.id, __instance.factory.transport.stationPool[__instance.stationId].id, __instance.factory.transport.stationPool[__instance.stationId].gid, StationUI.EUISettings.MinDeliverVessel, value); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -99,11 +99,11 @@ public static bool OnMinDeliverVesselValueChange_Prefix(UIStationWindow __instan [HarmonyPatch(nameof(UIStationWindow.OnWarperDistanceValueChange))] public static bool OnWarperDistanceValueChange_Prefix(UIStationWindow __instance, float value) { - if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || Multiplayer.Session.LocalPlayer.IsHost)) + if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost)) { StationUI packet = new StationUI(__instance.factory.planet.id, __instance.factory.transport.stationPool[__instance.stationId].id, __instance.factory.transport.stationPool[__instance.stationId].gid, StationUI.EUISettings.WarpDistance, value); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -116,11 +116,11 @@ public static bool OnWarperDistanceValueChange_Prefix(UIStationWindow __instance [HarmonyPatch(nameof(UIStationWindow.OnWarperNecessaryClick))] public static bool OnWarperNecessaryClick_Prefix(UIStationWindow __instance) { - if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || Multiplayer.Session.LocalPlayer.IsHost)) + if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost)) { StationUI packet = new StationUI(__instance.factory.planet.id, __instance.factory.transport.stationPool[__instance.stationId].id, __instance.factory.transport.stationPool[__instance.stationId].gid, StationUI.EUISettings.WarperNeeded, 0f); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -133,11 +133,11 @@ public static bool OnWarperNecessaryClick_Prefix(UIStationWindow __instance) [HarmonyPatch(nameof(UIStationWindow.OnIncludeOrbitCollectorClick))] public static bool OnIncludeOrbitCollectorClick_Prefix(UIStationWindow __instance) { - if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || Multiplayer.Session.LocalPlayer.IsHost)) + if (Multiplayer.IsActive && !Multiplayer.Session.Ships.PatchLockILS && (Multiplayer.Session.StationsUI.UIIsSyncedStage == 2 || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost)) { StationUI packet = new StationUI(__instance.factory.planet.id, __instance.factory.transport.stationPool[__instance.stationId].id, __instance.factory.transport.stationPool[__instance.stationId].gid, StationUI.EUISettings.IncludeCollectors, 0f); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -175,14 +175,14 @@ public static bool OnDroneIconClick_Prefix(UIStationWindow __instance) { toAdd = stationComponent.idleDroneCount * -1; } - if (!Multiplayer.Session.LocalPlayer.IsHost) + if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.StationsUI.UIRequestedShipDronWarpChange = true; } StationUI packet = new StationUI(__instance.factory.planet.id, stationComponent.id, stationComponent.gid, StationUI.EUISettings.SetDroneCount, stationComponent.idleDroneCount + toAdd); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -220,14 +220,14 @@ public static bool OnShipIconClick_Prefix(UIStationWindow __instance) { toAdd = stationComponent.idleShipCount * -1; } - if (!Multiplayer.Session.LocalPlayer.IsHost) + if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.StationsUI.UIRequestedShipDronWarpChange = true; } StationUI packet = new StationUI(__instance.factory.planet.id, stationComponent.id, stationComponent.gid, StationUI.EUISettings.SetShipCount, stationComponent.idleShipCount + toAdd); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -264,14 +264,14 @@ public static bool OnWarperIconClick_Prefix(UIStationWindow __instance) { toAdd = stationComponent.warperCount * -1; } - if (!Multiplayer.Session.LocalPlayer.IsHost) + if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.StationsUI.UIRequestedShipDronWarpChange = true; } StationUI packet = new StationUI(__instance.factory.planet.id, stationComponent.id, stationComponent.gid, StationUI.EUISettings.SetWarperCount, stationComponent.warperCount + toAdd); Multiplayer.Session.Network.SendPacket(packet); - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return true; } @@ -284,7 +284,7 @@ public static bool OnWarperIconClick_Prefix(UIStationWindow __instance) [HarmonyPatch(nameof(UIStationWindow.OnStationIdChange))] public static bool OnStationIdChange_Prefix(UIStationWindow __instance) { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.StationsUI.UIIsSyncedStage > 0 || GameMain.localPlanet == null || !__instance.active) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.StationsUI.UIIsSyncedStage > 0 || GameMain.localPlanet == null || !__instance.active) { return true; } @@ -326,7 +326,7 @@ public static bool OnStationIdChange_Prefix(UIStationWindow __instance) [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")] public static bool _OnUpdate_Prefix() { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.StationsUI.UIIsSyncedStage == 2) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || Multiplayer.Session.StationsUI.UIIsSyncedStage == 2) { return true; } @@ -338,7 +338,7 @@ public static bool _OnUpdate_Prefix() [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")] public static void _OnClose_Postfix(UIStationWindow __instance) { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } diff --git a/NebulaPatcher/Patches/Dynamic/UIStatisticsWindow_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIStatisticsWindow_Patch.cs index fcfa26a48..635122c11 100644 --- a/NebulaPatcher/Patches/Dynamic/UIStatisticsWindow_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIStatisticsWindow_Patch.cs @@ -13,7 +13,7 @@ class UIStatisticsWindow_Patch [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")] public static void _OnOpen_Postfix() { - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Statistics.IsStatisticsNeeded = true; Multiplayer.Session.Network.SendPacket(new StatisticsRequestEvent(StatisticEvent.WindowOpened)); @@ -25,7 +25,7 @@ public static void _OnOpen_Postfix() [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")] public static void _OnClose_Postfix() { - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost && Multiplayer.Session.Statistics.IsStatisticsNeeded) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost && Multiplayer.Session.Statistics.IsStatisticsNeeded) { Multiplayer.Session.Statistics.IsStatisticsNeeded = false; Multiplayer.Session.Network.SendPacket(new StatisticsRequestEvent(StatisticEvent.WindowClosed)); diff --git a/NebulaPatcher/Patches/Dynamic/UIStorageWindow_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIStorageWindow_Patch.cs index 324e04a7d..bdfdcfbc4 100644 --- a/NebulaPatcher/Patches/Dynamic/UIStorageWindow_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIStorageWindow_Patch.cs @@ -13,7 +13,7 @@ class UIStorageWindow_Patch [HarmonyPatch(nameof(UIStorageWindow.OnStorageIdChange))] public static bool OnStorageIdChange_Prefix(UIStorageWindow __instance) { - if (Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost && Multiplayer.Session.Storage.WindowOpened) + if (Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost && Multiplayer.Session.Storage.WindowOpened) { UIStorageGrid storageUI = __instance.storageUI; Multiplayer.Session.Storage.ActiveUIStorageGrid = storageUI; diff --git a/NebulaPatcher/Patches/Dynamic/VFInput_Patch.cs b/NebulaPatcher/Patches/Dynamic/VFInput_Patch.cs index 649c08c4c..37ffc0165 100644 --- a/NebulaPatcher/Patches/Dynamic/VFInput_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/VFInput_Patch.cs @@ -11,7 +11,7 @@ class VFInput_Patch [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")] public static bool _buildConfirm_Prefix(ref VFInput.InputValue __result) { - if (Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest.Value) { __result = default; __result.onDown = true; diff --git a/NebulaPatcher/Patches/Transpilers/BuildTool_Click_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/BuildTool_Click_Transpiler.cs index ac8a33289..3550b90ad 100644 --- a/NebulaPatcher/Patches/Transpilers/BuildTool_Click_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/BuildTool_Click_Transpiler.cs @@ -31,7 +31,7 @@ static IEnumerable CreatePrebuilds_Transpiler(IEnumerable>(() => { - return Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest && Multiplayer.Session.Factories.PacketAuthor != Multiplayer.Session.LocalPlayer.Id; + return Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest.Value && Multiplayer.Session.Factories.PacketAuthor != ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id; })) .InsertAndAdvance(new CodeInstruction(OpCodes.Brtrue, label)) .InstructionEnumeration(); diff --git a/NebulaPatcher/Patches/Transpilers/BuildTool_Path_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/BuildTool_Path_Transpiler.cs index 6179a3729..9f02a4d53 100644 --- a/NebulaPatcher/Patches/Transpilers/BuildTool_Path_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/BuildTool_Path_Transpiler.cs @@ -32,7 +32,7 @@ static IEnumerable CreatePrebuilds_Transpiler(IEnumerable>(() => { - return Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest && Multiplayer.Session.Factories.PacketAuthor != Multiplayer.Session.LocalPlayer.Id; + return Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest.Value && Multiplayer.Session.Factories.PacketAuthor != ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id; })) .CreateLabelAt(matcher.Pos + 19, out Label jmpLabel) .InsertAndAdvance(new CodeInstruction(OpCodes.Brtrue, jmpLabel)) diff --git a/NebulaPatcher/Patches/Transpilers/CargoTraffic_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/CargoTraffic_Transpiler.cs index 9a972aab1..53caee3b4 100644 --- a/NebulaPatcher/Patches/Transpilers/CargoTraffic_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/CargoTraffic_Transpiler.cs @@ -79,7 +79,7 @@ static IEnumerable IsPlanetPhysicsColliderDirty_Transpiler(IEnu .CreateLabelAt(matcher.Pos + 5, out Label end) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate>(() => { - return Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest; + return Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest.Value; })) .Insert(new CodeInstruction(OpCodes.Brtrue, end)) .Advance(5); diff --git a/NebulaPatcher/Patches/Transpilers/PlayerMove_Sail_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/PlayerMove_Sail_Transpiler.cs index dd7907103..5cdb86855 100644 --- a/NebulaPatcher/Patches/Transpilers/PlayerMove_Sail_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/PlayerMove_Sail_Transpiler.cs @@ -42,7 +42,7 @@ public static IEnumerable GameTick_Transpiler(IEnumerable PowerSystem_GameTick_Transpiler(IEnum { if (Multiplayer.IsActive) { - if (!Multiplayer.Session.LocalPlayer.IsHost) + if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { _this.nodePool[powerNodeId].requiredEnergy = _this.nodePool[powerNodeId].idleEnergyPerTick; // this gets added onto the known required energy by Multiplayer.Session.PowerTowers. and PowerSystem_Patch if (Multiplayer.Session.PowerTowers.AddRequested(_this.planet.id, powerNetId, powerNodeId, true, false)) @@ -84,7 +84,7 @@ public static IEnumerable PowerSystem_GameTick_Transpiler(IEnum { if (Multiplayer.IsActive) { - if (!Multiplayer.Session.LocalPlayer.IsHost) + if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { if (Multiplayer.Session.PowerTowers.AddRequested(_this.planet.id, powerNetId, powerNodeId, false, false)) { diff --git a/NebulaPatcher/Patches/Transpilers/StationComponent_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/StationComponent_Transpiler.cs index 48e1f9420..096fb12cc 100644 --- a/NebulaPatcher/Patches/Transpilers/StationComponent_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/StationComponent_Transpiler.cs @@ -66,7 +66,7 @@ public static IEnumerable RematchRemotePairs_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(RemoteLogisticOrder), nameof(RemoteLogisticOrder.thisIndex)))) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int index) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { List subscribers = Multiplayer.Session.StationsUI.GetSubscribers(stationComponent.planetId, stationComponent.id, stationComponent.gid); ILSRemoteOrderData packet = new ILSRemoteOrderData(stationComponent.gid, index, stationComponent.storage[index].remoteOrder); @@ -109,7 +109,7 @@ public static IEnumerable RematchRemotePairs_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldloc_S, 10)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, StationComponent[] gStationComponent, int n) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { int gIndex = stationComponent.workShipDatas[n].otherGId; StationStore[] storeArray = gStationComponent[gIndex]?.storage; @@ -153,7 +153,7 @@ public static IEnumerable RematchRemotePairs_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldloc_S, 14)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int index) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { List subscribers = Multiplayer.Session.StationsUI.GetSubscribers(stationComponent.planetId, stationComponent.id, stationComponent.gid); ILSRemoteOrderData packet = new ILSRemoteOrderData(stationComponent.gid, index, stationComponent.storage[index].remoteOrder); @@ -171,7 +171,7 @@ public static IEnumerable RematchRemotePairs_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldloc_S, 10)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, StationComponent[] gStationComponent, int n) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { int gIndex = stationComponent.workShipDatas[n].otherGId; StationStore[] storeArray = gStationComponent[gIndex]?.storage; @@ -199,7 +199,7 @@ public static IEnumerable RematchRemotePairs_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldloc_S, 18)) // this is the only difference .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int index) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { List subscribers = Multiplayer.Session.StationsUI.GetSubscribers(stationComponent.planetId, stationComponent.id, stationComponent.gid); ILSRemoteOrderData packet = new ILSRemoteOrderData(stationComponent.gid, index, stationComponent.storage[index].remoteOrder); @@ -217,7 +217,7 @@ public static IEnumerable RematchRemotePairs_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldloc_S, 10)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, StationComponent[] gStationComponent, int n) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { int gIndex = stationComponent.workShipDatas[n].otherGId; StationStore[] storeArray = gStationComponent[gIndex]?.storage; @@ -265,7 +265,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 51)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref ShipData shipData) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { ILSShipItems packet = new ILSShipItems(true, shipData.itemId, shipData.itemCount, shipData.shipIndex, stationComponent.gid); Multiplayer.Session.Network.SendPacketToStar(packet, GameMain.galaxy.PlanetById(stationComponent.planetId).star.id); @@ -289,7 +289,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 51)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref ShipData shipData) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { ILSShipItems packet = new ILSShipItems(true, shipData.itemId, shipData.itemCount, shipData.shipIndex, stationComponent.gid); Multiplayer.Session.Network.SendPacketToStar(packet, GameMain.galaxy.PlanetById(stationComponent.planetId).star.id); @@ -317,7 +317,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 51)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref ShipData shipData) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { ILSShipItems packet = new ILSShipItems(false, shipData.itemId, shipData.itemCount, shipData.shipIndex, stationComponent.gid); Multiplayer.Session.Network.SendPacketToStar(packet, GameMain.galaxy.PlanetById(stationComponent.planetId).star.id); @@ -353,7 +353,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 34)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int storageIndex, int amount) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { ILSShipItems packet = new ILSShipItems(false, stationComponent.storage[storageIndex].itemId, amount, 0, stationComponent.gid); Multiplayer.Session.Network.SendPacketToStar(packet, GameMain.galaxy.PlanetById(stationComponent.planetId).star.id); @@ -366,7 +366,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 42)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, long cost) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacketToStar(new ILSEnergyConsumeNotification(stationComponent.gid, cost), GameMain.galaxy.PlanetById(stationComponent.planetId).star.id); } @@ -386,7 +386,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 47)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int storageIndex, int amount) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { ILSShipItems packet = new ILSShipItems(false, stationComponent.storage[storageIndex].itemId, amount, 0, stationComponent.gid); Multiplayer.Session.Network.SendPacketToStar(packet, GameMain.galaxy.PlanetById(stationComponent.planetId).star.id); @@ -399,7 +399,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 42)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, long cost) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacketToStar(new ILSEnergyConsumeNotification(stationComponent.gid, cost), GameMain.galaxy.PlanetById(stationComponent.planetId).star.id); } @@ -432,7 +432,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 143)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int storageIndex, int amount) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { ILSShipItems packet = new ILSShipItems(false, stationComponent.storage[storageIndex].itemId, amount, 0, stationComponent.gid); Multiplayer.Session.Network.SendPacketToStar(packet, GameMain.galaxy.PlanetById(stationComponent.planetId).star.id); @@ -468,7 +468,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 27)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref SupplyDemandPair supplyDemandPair) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { List subscribers = Multiplayer.Session.StationsUI.GetSubscribers(stationComponent.planetId, stationComponent.id, stationComponent.gid); ILSRemoteOrderData packet = new ILSRemoteOrderData(stationComponent.gid, supplyDemandPair.demandIndex, stationComponent.storage[supplyDemandPair.demandIndex].remoteOrder); @@ -491,7 +491,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 46)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref SupplyDemandPair supplyDemandPair) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { List subscribers = Multiplayer.Session.StationsUI.GetSubscribers(stationComponent.planetId, stationComponent.id, stationComponent.gid); ILSRemoteOrderData packet = new ILSRemoteOrderData(stationComponent.gid, supplyDemandPair.demandIndex, stationComponent.storage[supplyDemandPair.demandIndex].remoteOrder); @@ -528,7 +528,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 27)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref SupplyDemandPair supplyDemandPair) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { List subscribers = Multiplayer.Session.StationsUI.GetSubscribers(stationComponent.planetId, stationComponent.id, stationComponent.gid); ILSRemoteOrderData packet = new ILSRemoteOrderData(stationComponent.gid, supplyDemandPair.demandIndex, stationComponent.storage[supplyDemandPair.demandIndex].remoteOrder); @@ -561,7 +561,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 27)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref SupplyDemandPair supplyDemandPair) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { List subscribers = Multiplayer.Session.StationsUI.GetSubscribers(stationComponent.planetId, stationComponent.id, stationComponent.gid); ILSRemoteOrderData packet = new ILSRemoteOrderData(stationComponent.gid, supplyDemandPair.demandIndex, stationComponent.storage[supplyDemandPair.demandIndex].remoteOrder); @@ -578,7 +578,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 42)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, long cost) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacketToStar(new ILSEnergyConsumeNotification(stationComponent.gid, cost), GameMain.galaxy.PlanetById(stationComponent.planetId).star.id); } @@ -617,7 +617,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(RemoteLogisticOrder), nameof(RemoteLogisticOrder.thisIndex)))) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int index) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { if (index > 4) { @@ -649,7 +649,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(RemoteLogisticOrder), nameof(RemoteLogisticOrder.otherIndex)))) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int index) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { if (index > 4) { @@ -681,7 +681,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(RemoteLogisticOrder), nameof(RemoteLogisticOrder.otherIndex)))) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int index) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { if (index > 4) { @@ -723,7 +723,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 142)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref SupplyDemandPair supplyDemandPair) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { List subscribers = Multiplayer.Session.StationsUI.GetSubscribers(stationComponent.planetId, stationComponent.id, stationComponent.gid); ILSRemoteOrderData packet = new ILSRemoteOrderData(stationComponent.gid, supplyDemandPair.demandIndex, stationComponent.storage[supplyDemandPair.demandIndex].remoteOrder); @@ -762,7 +762,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(RemoteLogisticOrder), nameof(RemoteLogisticOrder.thisIndex)))) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, int index) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { if (index > 4) { @@ -798,7 +798,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 51)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref ShipData shipData) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacket(new ILSShipUpdateWarperCnt(stationComponent.gid, shipData.shipIndex, shipData.warperCnt)); } @@ -821,7 +821,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, 51)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate((StationComponent stationComponent, ref ShipData shipData) => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacket(new ILSShipUpdateWarperCnt(stationComponent.gid, shipData.shipIndex, shipData.warperCnt)); } @@ -844,7 +844,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate>(stationComponent => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacket(new StationUI(stationComponent.planetId, stationComponent.id, stationComponent.gid, StationUI.EUISettings.SetWarperCount, stationComponent.warperCount, true)); } @@ -865,7 +865,7 @@ public static IEnumerable InternalTickRemote_Transpiler(IEnumer .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 138)) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate>(stationComponent => { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { Multiplayer.Session.Network.SendPacket(new StationUI(stationComponent.planetId, stationComponent.id, stationComponent.gid, StationUI.EUISettings.SetWarperCount, stationComponent.warperCount)); } diff --git a/NebulaPatcher/Patches/Transpilers/UIStatisticsWindow_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/UIStatisticsWindow_Transpiler.cs index 004d1bf7b..31c48fe7a 100644 --- a/NebulaPatcher/Patches/Transpilers/UIStatisticsWindow_Transpiler.cs +++ b/NebulaPatcher/Patches/Transpilers/UIStatisticsWindow_Transpiler.cs @@ -87,7 +87,7 @@ Since client does not have all factories loaded it would cause exceptions. .InsertAndAdvance(storeNum2Instruction) .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate>(() => { - return Multiplayer.IsActive && !Multiplayer.Session.LocalPlayer.IsHost; + return Multiplayer.IsActive && !((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost; })) .InsertAndAdvance(new CodeInstruction(OpCodes.Brtrue, endLabel)) .InstructionEnumeration(); diff --git a/NebulaPatcher/PluginInfo.cs b/NebulaPatcher/PluginInfo.cs index 60ddc0053..2b9f82051 100644 --- a/NebulaPatcher/PluginInfo.cs +++ b/NebulaPatcher/PluginInfo.cs @@ -1,9 +1,4 @@ -using System; -using System.Diagnostics; -using System.Linq; -using System.Reflection; - -namespace NebulaPatcher +namespace NebulaPatcher { /// /// The main metadata of the plugin. @@ -38,6 +33,6 @@ internal static class PluginInfo /// public const string PLUGIN_VERSION = ThisAssembly.AssemblyFileVersion; - public const string PLUGIN_DISPLAY_VERSION = ThisAssembly.IsPublicRelease ? ThisAssembly.AssemblyFileVersion : ThisAssembly.AssemblyInformationalVersion; + public const string PLUGIN_DISPLAY_VERSION = ThisAssembly.IsPublicRelease ? ThisAssembly.AssemblyVersion : ThisAssembly.AssemblyInformationalVersion; } } diff --git a/NebulaPatcher/Properties/launchsettings.json b/NebulaPatcher/Properties/launchsettings.json index 3b1a0d8e3..23e58af39 100644 --- a/NebulaPatcher/Properties/launchsettings.json +++ b/NebulaPatcher/Properties/launchsettings.json @@ -1,10 +1,10 @@ -{ +{ "profiles": { "Launch Dyson Sphere Program": { "commandName": "Executable", "executablePath": "$(DSPGameDir)DSPGAME.exe", "environmentVariables": { - "STEAM_APPID": "1366540" + "SteamAppId": "1366540" } } } diff --git a/NebulaWorld/Factory/BuildToolManager.cs b/NebulaWorld/Factory/BuildToolManager.cs index d8922c38e..ef006241f 100644 --- a/NebulaWorld/Factory/BuildToolManager.cs +++ b/NebulaWorld/Factory/BuildToolManager.cs @@ -1,4 +1,5 @@ -using NebulaModel.Logger; +using NebulaAPI; +using NebulaModel.Logger; using NebulaModel.Packets.Factory; using System; using System.Collections.Generic; @@ -21,7 +22,7 @@ public void CreatePrebuildsRequest(CreatePrebuildsRequest packet) PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId); if (planet.factory == null) { - if (Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.Session.Factories.IsIncomingRequest.Value) { // We only execute the code if the client has loaded the factory at least once. // Else it will get it once it goes to the planet for the first time. @@ -79,7 +80,7 @@ public void CreatePrebuildsRequest(CreatePrebuildsRequest packet) buildTool.factory = planet.factory; pab.factory = planet.factory; pab.noneTool.factory = planet.factory; - if (Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.Session.Factories.IsIncomingRequest.Value) { // Only the server needs to set these pab.planetPhysics = planet.physics; @@ -88,15 +89,15 @@ public void CreatePrebuildsRequest(CreatePrebuildsRequest packet) //Check if prebuilds can be build (collision check, height check, etc) bool canBuild = false; - if (Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.Session.Factories.IsIncomingRequest.Value) { GameMain.mainPlayer.mecha.buildArea = float.MaxValue; canBuild = CheckBuildingConnections(buildTool.buildPreviews, planet.factory.entityPool, planet.factory.prebuildPool); } - if (canBuild || Multiplayer.Session.Factories.IsIncomingRequest) + if (canBuild || Multiplayer.Session.Factories.IsIncomingRequest.Value) { - if (Multiplayer.Session.Factories.IsIncomingRequest) + if (Multiplayer.Session.Factories.IsIncomingRequest.Value) { CheckAndFixConnections(buildTool, planet); } @@ -152,8 +153,8 @@ public void CreatePrebuildsRequest(CreatePrebuildsRequest packet) buildTool.buildPreviews.AddRange(tmpList); } - Multiplayer.Session.Factories.TargetPlanet = FactoryManager.PLANET_NONE; - Multiplayer.Session.Factories.PacketAuthor = FactoryManager.AUTHOR_NONE; + Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE; + Multiplayer.Session.Factories.PacketAuthor = NebulaModAPI.AUTHOR_NONE; } } diff --git a/NebulaWorld/Factory/FactoryManager.cs b/NebulaWorld/Factory/FactoryManager.cs index 0d29e34cc..02c8ee33d 100644 --- a/NebulaWorld/Factory/FactoryManager.cs +++ b/NebulaWorld/Factory/FactoryManager.cs @@ -1,4 +1,5 @@ using BepInEx; +using NebulaAPI; using NebulaModel.DataStructures; using NebulaModel.Logger; using NebulaModel.Packets.Factory.Inserter; @@ -9,7 +10,7 @@ namespace NebulaWorld.Factory { - public class FactoryManager : IDisposable + public class FactoryManager : IFactoryManager { sealed class ThreadSafe { @@ -24,20 +25,17 @@ Locker GetPrebuildRequests(out Dictionary prebuildRequ Locker GetPlanetTimers(out Dictionary planetTimers) => threadSafe.PlanetTimers.GetLocked(out planetTimers); - public readonly ToggleSwitch IsIncomingRequest = new ToggleSwitch(); + private readonly ToggleSwitch isIncomingRequest = new ToggleSwitch(); + public IToggle IsIncomingRequest => isIncomingRequest; public PlanetFactory EventFactory { get; set; } public int PacketAuthor { get; set; } public int TargetPlanet { get; set; } - public const int PLANET_NONE = -2; - public const int AUTHOR_NONE = -1; - public const int STAR_NONE = -1; - public FactoryManager() { - PacketAuthor = AUTHOR_NONE; - TargetPlanet = PLANET_NONE; + PacketAuthor = NebulaModAPI.AUTHOR_NONE; + TargetPlanet = NebulaModAPI.PLANET_NONE; } public void Dispose() @@ -158,7 +156,7 @@ public void UnloadPlanetData(int planetId) public void InitializePrebuildRequests() { //Load existing prebuilds to the dictionary so it will be ready to build - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { using (GetPrebuildRequests(out var prebuildRequests)) { @@ -170,7 +168,7 @@ public void InitializePrebuildRequests() { if (factory.prebuildPool[i].id != 0) { - prebuildRequests[new PrebuildOwnerKey(factory.planetId, factory.prebuildPool[i].id)] = Multiplayer.Session.LocalPlayer.Id; + prebuildRequests[new PrebuildOwnerKey(factory.planetId, factory.prebuildPool[i].id)] = ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id; } } } @@ -224,7 +222,7 @@ public int GetNextPrebuildId(PlanetFactory factory) public void OnNewSetInserterPickTarget(int objId, int otherObjId, int inserterId, int offset, Vector3 pointPos) { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.Id == PacketAuthor) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id == PacketAuthor) { Multiplayer.Session.Network.SendPacketToLocalStar(new NewSetInserterPickTargetPacket(objId, otherObjId, inserterId, offset, pointPos, GameMain.localPlanet?.id ?? -1)); } @@ -232,7 +230,7 @@ public void OnNewSetInserterPickTarget(int objId, int otherObjId, int inserterId public void OnNewSetInserterInsertTarget(int objId, int otherObjId, int inserterId, int offset, Vector3 pointPos) { - if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.Id == PacketAuthor) + if (Multiplayer.IsActive && ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id == PacketAuthor) { Multiplayer.Session.Network.SendPacketToLocalStar(new NewSetInserterInsertTargetPacket(objId, otherObjId, inserterId, offset, pointPos, GameMain.localPlanet?.id ?? -1)); } diff --git a/NebulaWorld/Factory/PowerTowerManager.cs b/NebulaWorld/Factory/PowerTowerManager.cs index 15b6ce521..023cdd750 100644 --- a/NebulaWorld/Factory/PowerTowerManager.cs +++ b/NebulaWorld/Factory/PowerTowerManager.cs @@ -46,7 +46,7 @@ public void Dispose() public void GivePlayerPower() { - if (Multiplayer.Session.LocalPlayer.IsHost) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { // host gets it anyways return; diff --git a/NebulaWorld/GameDataHistory/GameDataHistoryManager.cs b/NebulaWorld/GameDataHistory/GameDataHistoryManager.cs index edd4b7c89..d2a8e3eff 100644 --- a/NebulaWorld/GameDataHistory/GameDataHistoryManager.cs +++ b/NebulaWorld/GameDataHistory/GameDataHistoryManager.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using System; namespace NebulaWorld.GameDataHistory @@ -10,6 +11,7 @@ public class GameDataHistoryManager : IDisposable public GameDataHistoryManager() { } + public void Dispose() { diff --git a/NebulaWorld/LocalPlayer.cs b/NebulaWorld/LocalPlayer.cs index 23175835e..9fda94aa0 100644 --- a/NebulaWorld/LocalPlayer.cs +++ b/NebulaWorld/LocalPlayer.cs @@ -1,16 +1,17 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using System; namespace NebulaWorld { - public class LocalPlayer : IDisposable + public class LocalPlayer : IDisposable, ILocalPlayer { public bool IsInitialDataReceived { get; private set; } public bool IsHost { get; set; } public bool IsClient => !IsHost; public bool IsNewPlayer { get; private set; } public ushort Id => Data.PlayerId; - public PlayerData Data { get; private set; } + public IPlayerData Data { get; private set; } public void SetPlayerData(PlayerData data, bool isNewPlayer) { diff --git a/NebulaWorld/Logistics/ILSShipManager.cs b/NebulaWorld/Logistics/ILSShipManager.cs index 87cc9056c..422652096 100644 --- a/NebulaWorld/Logistics/ILSShipManager.cs +++ b/NebulaWorld/Logistics/ILSShipManager.cs @@ -111,7 +111,7 @@ public void IdleShipGetToWork(ILSShipData packet) */ public void WorkShipBackToIdle(ILSShipData packet) { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } @@ -205,7 +205,7 @@ private void RequestgStationDockPos(int GId) */ public void UpdateRemoteOrder(ILSRemoteOrderData packet) { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { return; } @@ -230,7 +230,7 @@ public void UpdateRemoteOrder(ILSRemoteOrderData packet) */ public void AddTakeItem(ILSShipItems packet) { - if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || GameMain.data.galacticTransport.stationPool.Length <= packet.stationGID) + if (!Multiplayer.IsActive || ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || GameMain.data.galacticTransport.stationPool.Length <= packet.stationGID) { return; } @@ -283,7 +283,7 @@ public void UpdateSlotData(ILSUpdateSlotData packet) // Clients only care about what happens on their planet, hosts always need to apply this. // Using PlanetFactory to prevent getting the "fakes" that are creates on clients. - if (Multiplayer.Session.LocalPlayer.IsHost || (!Multiplayer.Session.LocalPlayer.IsHost && packet.PlanetId == GameMain.localPlanet?.id)) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost || (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost && packet.PlanetId == GameMain.localPlanet?.id)) { PlanetData pData = GameMain.galaxy.PlanetById(packet.PlanetId); StationComponent stationComponent = pData?.factory?.transport?.stationPool[packet.StationId]; diff --git a/NebulaWorld/Logistics/StationUIManager.cs b/NebulaWorld/Logistics/StationUIManager.cs index d1107edeb..3dea61f91 100644 --- a/NebulaWorld/Logistics/StationUIManager.cs +++ b/NebulaWorld/Logistics/StationUIManager.cs @@ -101,7 +101,7 @@ public void DecreaseCooldown() public void UpdateUI(StationUI packet) { - if ((UpdateCooldown == 0 || !packet.IsStorageUI) && Multiplayer.Session.LocalPlayer.IsHost) + if ((UpdateCooldown == 0 || !packet.IsStorageUI) && ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { UpdateCooldown = 10; if (packet.IsStorageUI) @@ -113,7 +113,7 @@ public void UpdateUI(StationUI packet) UpdateSettingsUI(packet); } } - else if (!Multiplayer.Session.LocalPlayer.IsHost) + else if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost) { if (packet.IsStorageUI) { diff --git a/NebulaWorld/MonoBehaviours/Local/LocalPlayerAnimation.cs b/NebulaWorld/MonoBehaviours/Local/LocalPlayerAnimation.cs index db7eef289..fe6b31ef8 100644 --- a/NebulaWorld/MonoBehaviours/Local/LocalPlayerAnimation.cs +++ b/NebulaWorld/MonoBehaviours/Local/LocalPlayerAnimation.cs @@ -32,7 +32,7 @@ void Update() Multiplayer.Session.Network.SendPacket(new PlayerAnimationUpdate() { - PlayerId = Multiplayer.Session.LocalPlayer.Id, + PlayerId = ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id, Idle = playerAnimator.idle.ToNebula(), RunSlow = playerAnimator.runSlow.ToNebula(), RunFast = playerAnimator.runFast.ToNebula(), diff --git a/NebulaWorld/MonoBehaviours/Local/LocalPlayerMovement.cs b/NebulaWorld/MonoBehaviours/Local/LocalPlayerMovement.cs index ba6794581..3e1455c12 100644 --- a/NebulaWorld/MonoBehaviours/Local/LocalPlayerMovement.cs +++ b/NebulaWorld/MonoBehaviours/Local/LocalPlayerMovement.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using NebulaModel.Packets.Players; using UnityEngine; @@ -31,9 +32,9 @@ void Update() var bodyRotation = new Float3(bodyTransform.eulerAngles); Double3 uPosition = new Double3(GameMain.mainPlayer.uPosition.x, GameMain.mainPlayer.uPosition.y, GameMain.mainPlayer.uPosition.z); - Multiplayer.Session.Network.SendPacket(new PlayerMovement(Multiplayer.Session.LocalPlayer.Id, GameMain.localPlanet?.id ?? -1, rootTransform.position.ToFloat3(), uPosition, rotation, bodyRotation)); + Multiplayer.Session.Network.SendPacket(new PlayerMovement(((LocalPlayer)Multiplayer.Session.LocalPlayer).Id, GameMain.localPlanet?.id ?? -1, rootTransform.position.ToFloat3(), uPosition, rotation, bodyRotation)); - PlayerData playerData = Multiplayer.Session.LocalPlayer.Data; + IPlayerData playerData = Multiplayer.Session.LocalPlayer.Data; playerData.BodyRotation = bodyRotation; playerData.LocalPlanetId = GameMain.localPlanet?.id ?? -1; playerData.LocalPlanetPosition = rootTransform.position.ToFloat3(); diff --git a/NebulaWorld/MonoBehaviours/Remote/RemotePlayerMovement.cs b/NebulaWorld/MonoBehaviours/Remote/RemotePlayerMovement.cs index 40bd11e08..46a9e37de 100644 --- a/NebulaWorld/MonoBehaviours/Remote/RemotePlayerMovement.cs +++ b/NebulaWorld/MonoBehaviours/Remote/RemotePlayerMovement.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using NebulaModel.Packets.Players; using NebulaModel.Utils; using NebulaWorld.MonoBehaviours.Local; diff --git a/NebulaWorld/Multiplayer.cs b/NebulaWorld/Multiplayer.cs index 7fe98d3ae..b5d83eae3 100644 --- a/NebulaWorld/Multiplayer.cs +++ b/NebulaWorld/Multiplayer.cs @@ -19,7 +19,7 @@ public static void HostGame(NetworkProvider server) IsLeavingGame = false; Session = new MultiplayerSession(server); - Session.Network.Start(); + ((NetworkProvider)Session.Network).Start(); } public static void JoinGame(NetworkProvider client) @@ -27,7 +27,7 @@ public static void JoinGame(NetworkProvider client) IsLeavingGame = false; Session = new MultiplayerSession(client); - Session.Network.Start(); + ((NetworkProvider)Session.Network).Start(); } public static void LeaveGame() diff --git a/NebulaWorld/MultiplayerSession.cs b/NebulaWorld/MultiplayerSession.cs index 3f2eb47e7..871f6c7bc 100644 --- a/NebulaWorld/MultiplayerSession.cs +++ b/NebulaWorld/MultiplayerSession.cs @@ -1,4 +1,5 @@ -using NebulaModel; +using NebulaAPI; +using NebulaModel; using NebulaModel.Logger; using NebulaWorld.Factory; using NebulaWorld.GameDataHistory; @@ -12,12 +13,12 @@ namespace NebulaWorld { - public class MultiplayerSession : IDisposable + public class MultiplayerSession : IDisposable, IMultiplayerSession { - public NetworkProvider Network { get; private set; } - public LocalPlayer LocalPlayer { get; private set; } + public NebulaAPI.INetworkProvider Network { get; private set; } + public ILocalPlayer LocalPlayer { get; private set; } public SimulatedWorld World { get; private set; } - public FactoryManager Factories { get; private set; } + public IFactoryManager Factories { get; private set; } public StorageManager Storage { get; private set; } public PowerTowerManager PowerTowers { get; private set; } public BeltManager Belts { get; private set; } @@ -117,7 +118,7 @@ public void OnGameLoadCompleted() Log.Info("Game load completed"); IsGameLoaded = true; - if (Multiplayer.Session.LocalPlayer.IsInitialDataReceived) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).IsInitialDataReceived) { Multiplayer.Session.World.SetupInitialPlayerState(); } diff --git a/NebulaWorld/NebulaWorld.csproj b/NebulaWorld/NebulaWorld.csproj index ec5392ea5..a0a71fb8d 100644 --- a/NebulaWorld/NebulaWorld.csproj +++ b/NebulaWorld/NebulaWorld.csproj @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/NebulaWorld/Player/DroneManager.cs b/NebulaWorld/Player/DroneManager.cs index 97340f0b5..19f838a30 100644 --- a/NebulaWorld/Player/DroneManager.cs +++ b/NebulaWorld/Player/DroneManager.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using NebulaModel.Packets.Players; using System; using System.Collections.Generic; @@ -48,7 +49,7 @@ public void BroadcastDroneOrder(int droneId, int entityId, int stage) { GameMain.mainPlayer.mecha.droneLogic.serving.Remove(entityId); } - Multiplayer.Session.Network.SendPacketToLocalPlanet(new NewDroneOrderPacket(GameMain.mainPlayer.planetId, droneId, entityId, Multiplayer.Session.LocalPlayer.Id, stage, priority, GameMain.localPlanet.factory.prebuildPool[-entityId].pos)); + Multiplayer.Session.Network.SendPacketToLocalPlanet(new NewDroneOrderPacket(GameMain.mainPlayer.planetId, droneId, entityId, ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id, stage, priority, GameMain.localPlanet.factory.prebuildPool[-entityId].pos)); } public void AddPlayerDronePlan(ushort playerId, int entityId) diff --git a/NebulaWorld/SimulatedWorld.cs b/NebulaWorld/SimulatedWorld.cs index 592da1501..386054d33 100644 --- a/NebulaWorld/SimulatedWorld.cs +++ b/NebulaWorld/SimulatedWorld.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using NebulaModel.Logger; using NebulaModel.Packets.Players; using NebulaModel.Packets.Session; @@ -64,16 +65,16 @@ public void SetupInitialPlayerState() return; } - if (!Multiplayer.Session.LocalPlayer.IsInitialDataReceived) + if (!((LocalPlayer)Multiplayer.Session.LocalPlayer).IsInitialDataReceived) { Log.Warn("Trying to setup initial player state before the player data was received!"); return; } - LocalPlayer player = Multiplayer.Session.LocalPlayer; + LocalPlayer player = ((LocalPlayer)Multiplayer.Session.LocalPlayer); // Assign our own color - UpdatePlayerColor(Multiplayer.Session.LocalPlayer.Id, player.Data.MechaColor); + UpdatePlayerColor(((LocalPlayer)Multiplayer.Session.LocalPlayer).Id, player.Data.MechaColor); // If not a new client, we need to update the player position to put him where he was previously if (player.IsClient && !player.IsNewPlayer) @@ -112,7 +113,7 @@ public void SetupInitialPlayerState() if (player.IsClient) { // Update player's Mecha tech bonuses - player.Data.Mecha.TechBonuses.UpdateMech(GameMain.mainPlayer.mecha); + ((MechaData)player.Data.Mecha).TechBonuses.UpdateMech(GameMain.mainPlayer.mecha); // Enable Ping Indicator for Clients DisplayPingIndicator(); @@ -149,7 +150,7 @@ public void OnAllPlayersSyncCompleted() GameMain.isFullscreenPaused = false; } - public void SpawnRemotePlayerModel(PlayerData playerData) + public void SpawnRemotePlayerModel(IPlayerData playerData) { using (GetRemotePlayersModels(out var remotePlayersModels)) { @@ -264,7 +265,7 @@ public void UpdatePlayerColor(ushort playerId, Float3 color) using (GetRemotePlayersModels(out var remotePlayersModels)) { Transform transform; - if (playerId == Multiplayer.Session.LocalPlayer.Id) + if (playerId == ((LocalPlayer)Multiplayer.Session.LocalPlayer).Id) { transform = GameMain.data.mainPlayer.transform; } @@ -291,7 +292,7 @@ public void UpdatePlayerColor(ushort playerId, Float3 color) } // We changed our own color, so we have to let others know - if (Multiplayer.Session.LocalPlayer.Id == playerId) + if (((LocalPlayer)Multiplayer.Session.LocalPlayer).Id == playerId) { Multiplayer.Session.Network.SendPacket(new PlayerColorChanged(playerId, color)); } @@ -523,7 +524,7 @@ public void RenderPlayerNameTagsInGame() } // If the player is not on the same planet or is in space, then do not render their in-world tag - if (playerModel.Movement.localPlanetId != Multiplayer.Session.LocalPlayer.Data.LocalPlanetId && playerModel.Movement.localPlanetId <= 0) + if (playerModel.Movement.localPlanetId != ((LocalPlayer)Multiplayer.Session.LocalPlayer).Data.LocalPlanetId && playerModel.Movement.localPlanetId <= 0) { playerNameText.SetActive(false); } diff --git a/NebulaWorld/Statistics/StatisticsManager.cs b/NebulaWorld/Statistics/StatisticsManager.cs index 118aaaeba..4a55c1dd4 100644 --- a/NebulaWorld/Statistics/StatisticsManager.cs +++ b/NebulaWorld/Statistics/StatisticsManager.cs @@ -1,4 +1,5 @@ -using NebulaModel.DataStructures; +using NebulaAPI; +using NebulaModel.DataStructures; using NebulaModel.Networking; using NebulaModel.Packets.Statistics; using System; diff --git a/README.md b/README.md index 598b6c079..4af06c198 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,10 @@ Please do keep in mind that this mod is still in heavy development, it may still - Stable version of the mod can be downloaded from [Thunderstore](https://dsp.thunderstore.io/package/nebula/NebulaMultiplayerMod/) (Recommended). - If you want to install the latest version of the mod, you can install pre-release versions be following the [installation guide](https://github.com/hubastard/nebula/wiki/Installing-a-pre-release-version). +## API Documentation + +This mod has an API, that makes it easier for other mod developers to make their mods compatible with Nebula. If you are a mod developer and you want your mods to be compatible, follow the instructions [here](https://github.com/hubastard/nebula/wiki/Nebula-mod-API). Also you can always join our [Discord Server](https://discord.gg/UHeB2QvgDa) for help with using the API. + ## What is the current status? The mod is in very early stages of development and still in a proof of concept state. Major refactors will happen while the project grows. Join the [Discord Server](https://discord.gg/UHeB2QvgDa) if you want to see to latest state of our development. diff --git a/thunderstore.toml b/thunderstore.toml new file mode 100644 index 000000000..5e4ae53ba --- /dev/null +++ b/thunderstore.toml @@ -0,0 +1,3 @@ +author_name = "nebula" +communities = ["dyson-sphere-program"] +has_nsfw_content = false diff --git a/version.json b/version.json index e75e962bf..ff6748a6d 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "0.4.0", + "version": "0.5.0", "assemblyVersion": { "precision": "build" },