using ExIni;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityInjector;
using UnityInjector.Attributes;
using System.Reflection;
namespace CM3D2.YetAnotherSoftDemosaic.Plugin
{
static internal class LINQExt {
public static void ForEach<T>(this IEnumerable<T> self , Action<T> act) {
foreach(var cur in self) act(cur);
}
}
public static class UnityExtensionsBridge {
static UnityExtensionsBridge() {
            klass = Type.GetType("UnityInjector.Extensions,UnityInjector");
}
static Type klass = null;
public static string UserDataPath {
get {
return (string)klass.GetMethod("get_UserDataPath").Invoke(null,null);
}
}
}
[PluginFilter("CM3D2x64"),
    PluginFilter("CM3D2x86"),
    PluginFilter("CM3D2VRx64"),
    PluginFilter("CM3D2OHx64"),
    PluginFilter("CM3D2OHx86"),
    PluginFilter("CM3D2OHVRx64"),
    PluginName("Yet Another Soft DeMosaic+CBL Patch"),
    PluginVersion("2.0.0.6")]
public class YASD : PluginBase
{
private Coroutine deMosaicCoroutine;
private bool runningCoroutine = false;
private bool allowChangeMosaic = true;
private KeyCode deMosaicHotKey = KeyCode.F4;
private bool isChubLip = false;
//1fで1秒
private const float WAIT_SECOND_DEMOSAIC = 0.5f;
/// <summary>
/// CM3D2のシーンリスト
/// </summary>
private enum Scene
{
/// <summary>メイド選択(夜伽、品評会の前など)</summary>
            SceneCharacterSelect = 1,
/// <summary>品評会</summary>
            SceneCompetitiveShow = 2,
/// <summary>昼夜メニュー、仕事結果</summary>
            SceneDaily = 3,
/// <summary>ダンス1</summary>
            SceneDance_DDFL = 4,
/// <summary>メイドエディット</summary>
            SceneEdit = 5,
/// <summary>メーカーロゴ</summary>
            SceneLogo = 6,
/// <summary>メイド管理</summary>
            SceneMaidManagement = 7,
/// <summary>ショップ</summary>
            SceneShop = 8,
/// <summary>タイトル画面</summary>
            SceneTitle = 9,
/// <summary>トロフィー閲覧</summary>
            SceneTrophy = 10,
/// <summary>???</summary>
            SceneTryInfo = 11,
/// <summary>主人公エディット</summary>
            SceneUserEdit = 12,
/// <summary>起動時警告画面</summary>
            SceneWarning = 13,
/// <summary>夜伽</summary>
            SceneYotogi = 14,
/// <summary>ADVパート(kgスクリプト処理)</summary>
            SceneADV = 15,
/// <summary>日付画面</summary>
            SceneStartDaily = 16,
/// <summary>タイトルに戻る</summary>
            SceneToTitle = 17,
/// <summary>MVP</summary>
            SceneSingleEffect = 18,
/// <summary>スタッフロール</summary>
            SceneStaffRoll = 19,
/// <summary>ダンス2</summary>
            SceneDance_ETYL = 20,
/// <summary>ダンス選択</summary>
            SceneDance_Selector = 21,
/// <summary>ダンス_3</summary>
            SceneDance_SL = 22,
/// <summary>デスクトップカスタム</summary>
            SceneEditDesk = 23,
/// <summary>回想</summary>
            SceneRecollection = 24,
/// <summary>メイドバトル</summary>
            SceneMaidBattle = 25,
/// <summary>ダンス_4</summary>
            SceneDance_SMT = 26,
/// <summary>撮影モード</summary>
            ScenePoser = 27,
/// <summary>ダンス5</summary>
            SceneDance_RTY_Release = 28,
/// <summary>エンパイアリーグ</summary>
            SceneEmpireLeague = 29,
/// <summary>ダンス6</summary>
            SceneDance_HHS_Release = 30,
/// <summary>ダンス7</summary>
            SceneDance_HHSx4_Release = 31,
/// <summary>ダンス8</summary>
            SceneDance_KNT_Release = 32,
/// <summary>ダンス9</summary>
            SceneDance_SSE_Release = 34,
/// <summary>ダンス10</summary>
            SceneDance_SSEx3_Release = 35
}
/// <summary>
/// CM3D2CBLのシーンリスト
/// </summary>
private enum SceneCBL
{
/// <summary>CBL:メイド選択(未使用?)</summary>
            SceneCharacterSelect = 1,
/// <summary>CBL:メニュー画面</summary>
            SceneMainMenuWithChubLip = 2,
/// <summary>CBL:ダンス1</summary>
            SceneDance_DDFL_Release = 3,
/// <summary>CBL:メイドエディット</summary>
            SceneEdit = 4,
/// <summary>CBL:メーカーロゴ(未使用?)</summary>
            SceneLogo = 5,
/// <summary>CBL:タイトル画面</summary>
            SceneTitle = 6,
/// <summary>CBL:???(未使用?)</summary>
            SceneTryInfo = 7,
/// <summary>CBL:主人公エディット</summary>
            SceneUserEdit = 8,
/// <summary>CBL:起動時警告画面</summary>
            SceneWarning = 9,
/// <summary>CBL:夜伽</summary>
            SceneYotogiWithChubLip = 10,
/// <summary>CBL:ADVパート(kgスクリプト処理)</summary>
            SceneADV = 11,
/// <summary>CBL:日付画面</summary>
            SceneStartDaily = 12,
/// <summary>CBL:タイトルに戻る</summary>
            SceneToTitle = 13,
/// <summary>CBL:MVP?(未使用?)</summary>
            SceneSingleEffect = 14,
/// <summary>CBL:スタッフロール?(未使用?)</summary>
            SceneStaffRoll = 15,
/// <summary>CBL:ダンス2</summary>
            SceneDance_ETYL_Release = 16,
/// <summary>CBL:ダンス選択</summary>
            SceneDanceSelect = 17,
/// <summary>CBL:ダンス3</summary>
            SceneDance_SCL_Release = 18,
/// <summary>CBL:デスクトップカスタム</summary>
            SceneDeskCustomize = 19,
/// <summary>CBL:ダンス4</summary>
            SceneDance_SMT_Release = 20,
/// <summary>CBL:撮影モード</summary>
            ScenePhotoMode = 21,
/// <summary>CBL:ダンス5</summary>
            SceneDance_RTY_Release = 22,
/// <summary>CBL:ダンス6</summary>
            SceneDance_HHS_Release = 23,
/// <summary>CBL:ダンス7</summary>
            SceneDance_HHSx4_Release = 24,
/// <summary>CBL:ダンス8</summary>
            SceneDance_KNT_Release = 25,
/// <summary>CBL:ダンス9</summary>
            SceneDance_SSE_Release = 26,
/// <summary>CBL:ダンス10</summary>
            SceneDance_SSEx3_Release = 27
}
/// <summary>
/// 3Dキャラが描画されるレベル
/// </summary>
private enum EnableLevel
{
/// <summary>品評会</summary>
            SceneCompetitiveShow = 2,
/// <summary>ダンス1</summary>
            SceneDance_DDFL = 4,
/// <summary>メイドエディット</summary>
            SceneEdit = 5,
/// <summary>ショップ</summary>
            SceneShop = 8,
/// <summary>夜伽</summary>
            SceneYotogi = 14,
/// <summary>ADVパート(kgスクリプト処理)</summary>
            SceneADV = 15,
/// <summary>MVP</summary>
            SceneSingleEffect = 18,
/// <summary>ダンス2</summary>
            SceneDance_ETYL = 20,
/// <summary>ダンス_3</summary>
            SceneDance_SL = 22,
/// <summary>回想</summary>
            SceneRecollection = 24,
/// <summary>メイドバトル</summary>
            SceneMaidBattle = 25,
/// <summary>ダンス_4</summary>
            SceneDance_SMT = 26,
/// <summary>撮影モード</summary>
            ScenePoser = 27,
/// <summary>ダンス5</summary>
            SceneDance_RTY_Release = 28,
/// <summary>エンパイアリーグ</summary>
            SceneEmpireLeague = 29,
/// <summary>ダンス6</summary>
            SceneDance_HHS_Release = 30,
/// <summary>ダンス7</summary>
            SceneDance_HHSx4_Release = 31,
/// <summary>ダンス8</summary>
            SceneDance_KNT_Release = 32,
/// <summary>ダンス9</summary>
            SceneDance_SSE_Release = 34,
/// <summary>ダンス10</summary>
            SceneDance_SSEx3_Release = 35
}
/// <summary>
/// 3Dキャラが描画されるレベル Chu-B Lip
/// </summary>
private enum EnableLevelCBL
{
/// <summary>CBL:メニュー画面</summary>
            SceneMainMenuWithChubLip = 2,
/// <summary>CBL:ダンス1</summary>
            SceneDance_DDFL_Release = 3,
/// <summary>CBL:メイドエディット</summary>
            SceneEdit = 4,
/// <summary>CBL:主人公エディット</summary>
            SceneUserEdit = 8,
/// <summary>CBL:夜伽/チュートリアル感度調整モード</summary>
            SceneYotogiWithChubLip = 10,
/// <summary>CBL:ADVパート(kgスクリプト処理)</summary>
            SceneADV = 11,
/// <summary>CBL:ダンス2</summary>
            SceneDance_ETYL_Release = 16,
/// <summary>CBL:ダンス3</summary>
            SceneDance_SCL_Release = 18,
/// <summary>CBL:ダンス4</summary>
            SceneDance_SMT_Release = 20,
/// <summary>CBL:撮影モード</summary>
            ScenePhotoMode = 21,
/// <summary>CBL:ダンス5</summary>
            SceneDance_RTY_Release = 22,
/// <summary>CBL:ダンス6</summary>
            SceneDance_HHS_Release = 23,
/// <summary>CBL:ダンス7</summary>
            SceneDance_HHSx4_Release = 24,
/// <summary>CBL:ダンス8</summary>
            SceneDance_KNT_Release = 25,
/// <summary>CBL:ダンス9</summary>
            SceneDance_SSE_Release = 26,
/// <summary>CBL:ダンス10</summary>
            SceneDance_SSEx3_Release = 27
}
/// <summary>
/// 男キャラやおもちゃが出現するレベル
/// </summary>
private enum ShowMenOrToysLevel
{
/// <summary>夜伽</summary>
            SceneYotogi = 14,
/// <summary>ADVパート(kgスクリプト処理)</summary>
            SceneADV = 15,
/// <summary>撮影モード</summary>
            ScenePoser = 27
}
/// <summary>
/// 男キャラやおもちゃが出現するレベル Chu-B Lip
/// </summary>
private enum ShowMenOrToysLevelCBL
{
/// <summary>CBL:夜伽/チュートリアル感度調整モード</summary>
            SceneYotogiWithChubLip = 10,
/// <summary>CBL:ADVパート(kgスクリプト処理)</summary>
            SceneADV = 11,
/// <summary>CBL:撮影モード</summary>
            ScenePhotoMode = 21
}
/// <summary>
/// メイドが出現するがキャラ変更や着替えを行わないレベル
/// </summary>
private enum NotChangeMaidsLevel
{
/// <summary>品評会</summary>
            SceneCompetitiveShow = 2,
/// <summary>ダンス1</summary>
            SceneDance_DDFL = 4,
/// <summary>MVP</summary>
            SceneSingleEffect = 18,
/// <summary>ダンス2</summary>
            SceneDance_ETYL = 20,
/// <summary>ダンス3</summary>
            SceneDance_SL = 22,
/// <summary>ダンス4</summary>
            SceneDance_SMT = 26,
/// <summary>ダンス5</summary>
            SceneDance_RTY_Release = 28,
/// <summary>エンパイアリーグ</summary>
            SceneEmpireLeague = 29,
/// <summary>ダンス6</summary>
            SceneDance_HHS_Release = 30,
/// <summary>ダンス7</summary>
            SceneDance_HHSx4_Release = 31,
/// <summary>ダンス8</summary>
            SceneDance_KNT_Release = 32,
/// <summary>ダンス9</summary>
            SceneDance_SSE_Release = 34,
/// <summary>ダンス10</summary>
            SceneDance_SSEx3_Release = 35
}
/// <summary>
/// メイドが出現するがキャラ変更や着替えを行わないレベル Chu-B Lip
/// </summary>
private enum NotChangeMaidsLevelCBL
{
/// <summary>CBL:ダンス1</summary>
            SceneDance_DDFL_Release = 3,
/// <summary>CBL:ダンス2</summary>
            SceneDance_ETYL_Release = 16,
/// <summary>CBL:ダンス3</summary>
            SceneDance_SCL_Release = 18,
/// <summary>CBL:ダンス4</summary>
            SceneDance_SMT_Release = 20,
/// <summary>CBL:ダンス5</summary>
            SceneDance_RTY_Release = 22,
/// <summary>CBL:ダンス6</summary>
            SceneDance_HHS_Release = 23,
/// <summary>CBL:ダンス7</summary>
            SceneDance_HHSx4_Release = 24,
/// <summary>CBL:ダンス8</summary>
            SceneDance_KNT_Release = 25,
/// <summary>CBL:ダンス9</summary>
            SceneDance_SSE_Release = 26,
/// <summary>CBL:ダンス10</summary>
            SceneDance_SSEx3_Release = 27
}
private DeMosaic deMosaic = new DeMosaic();
private void LoadConfig()
{
            IniKey changeMosaic = Preferences["DeMosaic"]["ChangeMode"];
            IniKey target = Preferences["DeMosaic"]["Target"];
            IniKey changeMosaicKey = Preferences["DeMosaic"]["HotKey"];
string dataPath = Application.dataPath;
            isChubLip = dataPath.Contains("CM3D2OH");
if (changeMosaic == null || string.IsNullOrEmpty(changeMosaic.Value))
{
                changeMosaic.Value = allowChangeMosaic.ToString();
                SaveConfig();
}
else
{
if (!bool.TryParse(changeMosaic.Value, out allowChangeMosaic))
{
                    changeMosaic.Value = allowChangeMosaic.ToString();
                    SaveConfig();
}
}
if (target == null || string.IsNullOrEmpty(target.Value))
{
                target.Value = deMosaic.Target.ToString();
                SaveConfig();
}
else
{
if (Enum.IsDefined(typeof(DeMosaic.Switch), target.Value))
{
                    deMosaic.Target = (DeMosaic.Switch)Enum.Parse(typeof(DeMosaic.Switch), target.Value, true);
}
else
{
                    target.Value = deMosaic.Target.ToString();
                    SaveConfig();
}
}
if (changeMosaicKey == null || string.IsNullOrEmpty(changeMosaicKey.Value))
{
                changeMosaicKey.Value = deMosaicHotKey.ToString();
                SaveConfig();
}
else
{
if (Enum.IsDefined(typeof(KeyCode), changeMosaicKey.Value))
{
                    deMosaicHotKey = (KeyCode)Enum.Parse(typeof(KeyCode), changeMosaicKey.Value, true);
}
else
{
                    changeMosaicKey.Value = deMosaicHotKey.ToString();
                    SaveConfig();
}
}
}
private void Awake()
{
            GameObject.DontDestroyOnLoad(this);
System.Diagnostics.Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
            LoadConfig();
            StartCoroutine(GetKeyInput());
}
private void OnLevelWasLoaded(int level)
{
if (runningCoroutine)
{
System.Diagnostics.Debug.WriteLine("Demosaic Coroutine stop.");
                StopCoroutine(deMosaicCoroutine);
                runningCoroutine = false;
}
if ((isChubLip && Enum.IsDefined(typeof(EnableLevelCBL), level)) || (!isChubLip && Enum.IsDefined(typeof(EnableLevel), level)))
{
System.Diagnostics.Debug.WriteLine("Demosaic Coroutine start.");
                deMosaicCoroutine = StartCoroutine(DeMosaicCoroutine(level));
                runningCoroutine = true;
}
}
private IEnumerator GetKeyInput()
{
while (true)
{
if (Input.GetKeyDown(deMosaicHotKey) && allowChangeMosaic)
{
                    deMosaic.Target++;
                    Console.WriteLine("YADSM Target:{0}", deMosaic.Target.ToString());
}
yield return null;
}
}
private IEnumerator DeMosaicCoroutine(int level)
{
while (true)
{
bool result = deMosaic.DeMosaicMaids();
if (result && !allowChangeMosaic && Enum.IsDefined(typeof(NotChangeMaidsLevel), level))
{
System.Diagnostics.Debug.WriteLine("DeMosaic Coroutine Break.");
                    runningCoroutine = false;
yield break;
}
yield return null;
if ((isChubLip && Enum.IsDefined(typeof(ShowMenOrToysLevelCBL), level)) || (!isChubLip &&Enum.IsDefined(typeof(ShowMenOrToysLevel), level)))
{
                    deMosaic.DeMosaicToys();
yield return null;
                    deMosaic.DeMosaicMen();
}
("DeMosaic Coroutine Continue.");
yield return new WaitForSeconds(WAIT_SECOND_DEMOSAIC);
}
}
public void OnApplicationQuit()
{
            Preferences["DeMosaic"]["Target"].Value = deMosaic.Target.ToString();
            SaveConfig();
}
}
public class DeMosaic
{
public enum Switch
{
            None,
            Maid,
            MaidAndItem,
            All,
            Max
}
private Switch _target = Switch.All;
public Switch Target
{
get { return _target; }
set { _target = value == Switch.Max ? Switch.None : value; }
}
private Shader shaderTransparent;
private Shader shaderMosaic;
private bool isChubLip = false;
public DeMosaic() {
            shaderTransparent = Shader.Find("CM3D2/Toony_Lighted_Trans");
            shaderMosaic = Shader.Find("CM3D2/Mosaic");
}
private string getHiraerchy(Transform t)
{
string hiraerchy = "/" + t.name;
while (t.parent)
{
                t = t.parent;
                hiraerchy = "/" + t.name + hiraerchy;
}
return hiraerchy;
}
private Renderer[] GetMosaicRenderer(string type)
{
            GameObject alloffset = GameObject.Find("__GameMain__/Character/Active/AllOffset");
if (!alloffset)
{
return null;
}
            Renderer[] mosaic = alloffset.GetComponentsInChildren<Renderer>(true)
.Where(_ => _.materials.Any(m => m.name.Contains("moza")))
.ToArray();
string s;
if (type.Equals("toy"))
{
return mosaic
.Where(_ => _.materials.Any(m => m.name != "moza"))
.ToArray();
}
else if (type.Equals("man"))
{
                s = "Man[";
}
else if (type.Equals("maid"))
{
                s = "Maid[";
}
else
{
                Console.WriteLine("YASD.GetMosaicRenderer: Argument error.");
return null;
}
return mosaic
.Where(_ => _.name.Equals("moza"))
.Where(_ => getHiraerchy(_.transform).Contains(s))
.ToArray();
}
private Renderer[] GetMaidsMosaicRenderer()
{
return GetMosaicRenderer("maid");
}
private Renderer[] GetMenMosaicRenderer()
{
return GetMosaicRenderer("man");
}
private Renderer[] GetToysMosaicRenderer()
{
return GetMosaicRenderer("toy");
}
public bool DeMosaicMaids()
{
bool result = false;
            Renderer[] maidsMosaicList = GetMaidsMosaicRenderer();
if (maidsMosaicList != null)
{
                result = HumanMosaicSwitcher(maidsMosaicList, (Target == DeMosaic.Switch.None));
}
return result;
}
public void DeMosaicMen()
{
            Renderer[] menMosaicList = GetMenMosaicRenderer();
if (menMosaicList != null)
{
                HumanMosaicSwitcher(menMosaicList, (Target != DeMosaic.Switch.All));
}
}
private bool HumanMosaicSwitcher(Renderer[] mosaic, bool enableMosaic)
{
bool result = false;
if (mosaic == null)
{
return result;
}
            mosaic.Where(_ => _.enabled == !enableMosaic).ForEach(_ =>
{
                _.enabled = enableMosaic;
System.Diagnostics.Debug.WriteLine(string.Format("{0}'s Mosaic Enable:{1}", _.name, enableMosaic));
                result = true;
});
return result;
}
public void DeMosaicToys()
{
            Renderer[] rs = GetToysMosaicRenderer();
if (rs != null)
{
foreach (Renderer r in rs)
{
                    ToyMaterialChanger(r);
}
}
//GameObject boxdildo = UTY.GetChildObject(GameMain.Instance.BgMgr.current_bg_object, "ディルド&台", true);
//if (boxdildo == null)
//    return;
try
{
                Renderer[] mosaic = GameMain.Instance.BgMgr.current_bg_object.GetComponentsInChildren<Renderer>(true)
.Where(_ => _.materials.Any(m => m.name.Contains("moza")))
.ToArray();
if (mosaic != null)
{
foreach (Renderer r in mosaic)
{
                    ToyMaterialChanger(r);
}
}
}
catch { /*LogError(ex);*/ }
}
private void ToyMaterialChanger(Renderer mosaic)
{
if (mosaic.materials.Length == 1)
{
return;
}
bool mosaicDisable = Target >= DeMosaic.Switch.MaidAndItem;
            mosaic.materials
.Where(_ => mosaicDisable ? _.shader.Equals(shaderMosaic) : _.shader.Equals(shaderTransparent))
.ForEach(_ =>
{
                    _.shader = mosaicDisable ? shaderTransparent : shaderMosaic;
                    _.color += mosaicDisable ? new Color(0f, 0f, 0f, -1f) : new Color(0f, 0f, 0f, 1f);
});
}
}
}
RAW Paste Data

共 0 則回應

馬上回應搶第 1 樓...
回應...