Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
[TextureModifier] The mod should work fine now!
Browse files Browse the repository at this point in the history
  • Loading branch information
REHERC committed Jun 1, 2020
1 parent 85b7cf1 commit 72e9bc7
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
6 changes: 5 additions & 1 deletion Distance.TextureModifier.Content/Mod/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"Contact": "Github: @REHERC",
"ModuleFileName": "Distance.TextureModifier.dll",
"Dependencies": [],
"RequiredGSLs": [
"com.github.reherc/Centrifuge.Distance"
],
"SkipLoad": false,
"Priority": 10
}
}

10 changes: 5 additions & 5 deletions Distance.TextureModifier/Declarations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ public static bool IsBlacklisted(Material material)
"_Splat3",
"_SSAO",
"_StaticTex",
//"_SubtractiveTex",
//"_TeleTex",
"_SubtractiveTex",
"_TeleTex",
"_Tex",
//"_TranslucencyMap",
"_TranslucencyMap",
///"_UpTex",
"_VignetteTex",
"_ZCurve",
"NoiseTex",
//"StarColor",
//"StartColor"
"StarColor",
"StartColor"
};
}
}
50 changes: 39 additions & 11 deletions Distance.TextureModifier/Distance.TextureModifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -39,12 +41,19 @@
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\Distance.Assemblies\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp.dev">
<Reference Include="Assembly-CSharp.dev, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Distance.Assemblies\Assembly-CSharp.dev.dll</HintPath>
</Reference>
<Reference Include="Centrifuge.Distance, Version=1.0.12.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.1.0.12\lib\net35\Centrifuge.Distance.dll</HintPath>
</Reference>
<Reference Include="LitJSON, Version=0.15.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LitJson.0.15.0\lib\net35\LitJSON.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=1.7.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.1.0.12\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="Reactor.API, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.Mod.SDK.2.2.0\lib\net35\Reactor.API.dll</HintPath>
</Reference>
Expand All @@ -54,16 +63,19 @@
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\Distance.Assemblies\UnityEngine.dll</HintPath>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.1.0.12\lib\net35\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.1.0.12\lib\net35\UnityEngine.Networking.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\Distance.Assemblies\UnityEngine.UI.dll</HintPath>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Centrifuge.GameSupport.Distance.1.0.12\lib\net35\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Declarations.cs" />
<Compile Include="Entry.cs" />
<Compile Include="Mod.cs" />
<Compile Include="Harmony\Assembly-CSharp\Resource\LoadPrefab.cs" />
<Compile Include="Harmony\Assembly-CSharp\Resource\LoadLevelPreviewTexture.cs" />
<Compile Include="Harmony\Assembly-CSharp\Resource\LoadTextureFromFile.cs" />
Expand All @@ -72,24 +84,35 @@
<Compile Include="TextureLoader.cs" />
</ItemGroup>
<ItemGroup>
<None Include="mod.json" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="..\Distance.Shared\Distance.Shared.projitems" Label="Shared" />
<Import Project="..\Distance.TextureModifier.Content\Distance.TextureModifier.Content.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>SET INCLUDE=$(SolutionDir)Distance.TextureModifier.Content
<PostBuildEvent>SET MODNAME=Distance Texture Modifier
SET INCLUDE=$(SolutionDir)Distance.TextureModifier.Content

SET BUILD=$(ProjectDir)$(OutDir)
SET PACKAGES=$(SolutionDir)Build\Distance Texture Modifier
SET PACKAGES=$(SolutionDir)Build\%25MODNAME%25\Centrifuge

CALL :MAKEDIR "%25PACKAGES%25"
SET MOD=%25PACKAGES%25\Mods\%25MODNAME%25

CALL :COPYDIR "%25INCLUDE%25\Mod" "%25PACKAGES%25"
CALL :COPY "%25BUILD%25Distance.TextureModifier.dll" "%25PACKAGES%25"
REM ===== COPY MOD FILES =====

CALL :MAKEDIR "%25MOD%25"

CALL :COPYDIR "%25INCLUDE%25\Mod" "%25MOD%25"
CALL :COPY "%25BUILD%25Distance.TextureModifier.dll" "%25MOD%25"

CALL :INCLUDEGSL Centrifuge.Distance

EXIT 0

REM ===== BUILD SUBROUTINES =====

:MAKEDIR
IF NOT EXIST %251 MKDIR %251
GOTO :EOF
Expand All @@ -100,6 +123,11 @@ GOTO :EOF

:COPYDIR
XCOPY /i /s /Y /v %251 %252
GOTO :EOF

:INCLUDEGSL
CALL :MAKEDIR "%25PACKAGES%25\GameSupport"
CALL :COPY "%25BUILD%25%251.dll" "%25PACKAGES%25\GameSupport"
GOTO :EOF</PostBuildEvent>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class Resource__LoadLevelPreviewTexture
[HarmonyPostfix]
internal static void Postfix(ref Texture __result)
{
__result = Object.Instantiate(Entry.Instance.Loader.GetRandomTexture());
__result = Object.Instantiate(Mod.Instance.Loader.GetRandomTexture());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class Resource__LoadPrefab
[HarmonyPostfix]
internal static void Postfix(ref GameObject __result)
{
Entry.Instance.Modifier.Patch(__result);
Mod.Instance.Modifier.Patch(__result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class Resource__LoadTextureFromFile
[HarmonyPostfix]
internal static void Postfix(ref Texture __result)
{
__result = Object.Instantiate(Entry.Instance.Loader.GetRandomTexture());
__result = Object.Instantiate(Mod.Instance.Loader.GetRandomTexture());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using Reactor.API.Attributes;
using Centrifuge.Distance.Game;
using Centrifuge.Distance.GUI.Data;
using Reactor.API.Attributes;
using Reactor.API.Interfaces.Systems;
using Reactor.API.Logging;
using Reactor.API.Storage;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using UnityEngine;

namespace Distance.TextureModifier
{
[ModEntryPoint("com.distance.reherc/texturemodifier")]
public class Entry : MonoBehaviour
[ModEntryPoint("com.github.reherc/Distance.TextureModifier")]
public class Mod : MonoBehaviour
{
public static Entry Instance;
public static Mod Instance;

public IManager Manager { get; set; }

Expand All @@ -28,6 +32,7 @@ public void Initialize(IManager manager)
{
Instance = this;
Manager = manager;

Data = new FileSystem();

Logger = LogManager.GetForCurrentAssembly();
Expand All @@ -40,6 +45,8 @@ public void Initialize(IManager manager)

Events.Managers.AwakeGameManager.Subscribe(LateInitialize);
Events.Level.PostLoad.Subscribe(LevelPostLoad);

CreateMenus();
}

internal void LateInitialize(Events.Managers.AwakeGameManager.Data data)
Expand All @@ -49,10 +56,24 @@ internal void LateInitialize(Events.Managers.AwakeGameManager.Data data)
StartCoroutine(ReskinResourcePrefabs());
}

public void CreateMenus()
{
MenuTree menu = new MenuTree("texturemodifier#main.menu", "Texture Modifier");

menu.ActionButton(
MenuDisplayMode.Both,
"texturemodifier#main.menu/datafolder-open",
"OPEN DATA FOLDER",
() => { Process.Start(Path.Combine(Data.RootDirectory, "Data")); },
"Open the folder used to load textures."
);

Menus.AddNew(MenuDisplayMode.Both, menu, "Settings for the Texture Modifier mod");
}

public void Load()
{
Loader.ClearResources(true);
Loader.LoadTextures("Textures");
Loader.Load();
}

internal void LevelPostLoad(Events.Level.PostLoad.Data data)
Expand All @@ -69,7 +90,7 @@ internal IEnumerator ReskinResourcePrefabs()

objects.AddRange(FindObjectsOfType<GameObject>());
objects.AddRange(Resources.FindObjectsOfTypeAll<GameObject>());
objects.AddRange(Resource.LoadAllInFolder<GameObject>(Resource.prefabsFolder_).Cast<GameObject>());

objects.AddRange(Resource.LoadAllInFolder<GameObject>(Resource.editorPrefabsFolder_).Cast<GameObject>());
objects.AddRange(Resource.LoadAllInFolder<GameObject>(Resource.splineRoadTemplatesFolder_).Cast<GameObject>());
objects.AddRange(Resource.LoadAllInFolder<GameObject>(Resource.splineTunnelTemplatesFolder_).Cast<GameObject>());
Expand Down
16 changes: 2 additions & 14 deletions Distance.TextureModifier/ResourceModificator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ public void PatchMaterial(Material material)

foreach (var property in Declarations.materialTextureProperties)
{
if (material.HasProperty(property))
{
applyPatch = true;
break;
}
applyPatch = true;
break;
}

if (applyPatch)
Expand Down Expand Up @@ -106,15 +103,6 @@ public void PatchRenderer(Renderer renderer)
PatchMaterial(renderer.sharedMaterial);
PatchMaterials(renderer.sharedMaterials);

/*
Material material = textureLoader_.GetRandomMaterial();
ReplaceMaterials(renderer.materials, material);
ReplaceMaterials(renderer.sharedMaterials, material);
renderer.material = material;
renderer.sharedMaterial = material;
*/
break;
}
}
Expand Down
12 changes: 8 additions & 4 deletions Distance.TextureModifier/TextureLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public TextureLoader(FileSystem fileSystem)
materials = new Object[0];
}

public void Load(bool gc = false)
{
ClearResources(gc);
LoadTextures("Textures");
}

public void ClearResources(bool garbageCollect = false)
{
ClearResources(ref textures);
Expand Down Expand Up @@ -120,8 +126,7 @@ public Texture2D GetRandomTexture(int stack = 10)
}
else
{
ClearResources();
LoadTextures("Textures");
Load(true);
return GetRandomTexture(stack - 1);
}
}
Expand All @@ -143,8 +148,7 @@ public Material GetRandomMaterial(int stack = 10)
}
else
{
ClearResources();
LoadTextures("Textures");
Load(true);
return GetRandomMaterial(stack - 1);
}
}
Expand Down
12 changes: 12 additions & 0 deletions Distance.TextureModifier/mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"FriendlyName": "<mod_friendly_name>",
"Author": "<mod_author>",
"Contact": "<author_contact>",
"ModuleFileName": "MySuperMod.dll",
"Priority": 10,
"SkipLoad": false,
"Dependencies": [],
"RequiredGSLs": [
"com.github.reherc/Centrifuge.Distance"
]
}
1 change: 1 addition & 0 deletions Distance.TextureModifier/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Centrifuge.GameSupport.Distance" version="1.0.12" targetFramework="net35" />
<package id="Centrifuge.Mod.SDK" version="2.2.0" targetFramework="net35" />
<package id="Lib.Harmony" version="1.2.0.1" targetFramework="net35" />
<package id="LitJson" version="0.15.0" targetFramework="net35" />
Expand Down

0 comments on commit 72e9bc7

Please sign in to comment.