InOutAnimation.cs 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text.RegularExpressions;
  8. using System.Xml;
  9. using System.Xml.Serialization;
  10. using UnityEngine;
  11. using UnityEngine.Rendering;
  12. using UnityEngine.SceneManagement;
  13. using UnityInjector;
  14. using UnityInjector.Attributes;
  15. using static UnityEngine.GUILayout;
  16. using Debug = UnityEngine.Debug;
  17. namespace COM3D2.InOutAnimation.Plugin
  18. {
  19. [
  20. PluginFilter(PluginFilter),
  21. PluginName(PluginName),
  22. PluginVersion(PluginVersion)
  23. ]
  24. public class InOutAnimation : PluginBase
  25. {
  26. private const string PluginFilter = "com3d2x64",
  27. PluginName = "InOutAnimation",
  28. PluginVersion = "0.0.0.0";
  29. private const string PathConfig = @"IOAnim",
  30. FileNameConfig = @"Settings";
  31. private const string ConfigPanel = "ConfigPanel";
  32. private const string ResultPanel = "ResultPanel";
  33. private const string NameHideScrollField = "current_panel_display_",
  34. NameSkillSel = "SkillSelectViewer",
  35. NameParamView = "ParameterViewer";
  36. private const string HiddenShader = "Hidden/Internal-Colored";
  37. private const string NoZTestShader = "CM3D2/Toony_Lighted_Trans_NoZTest";
  38. private const string SE_CumShot = "SE016";
  39. #region Variables
  40. private readonly Version pluginGameVer = new Version("1.32.0");
  41. private Version currentGameVer;
  42. private bool isStudioMode;
  43. private Mediator mediator;
  44. private AnmScript script;
  45. private State current;
  46. private FlipAnim[] flipAnims;
  47. private PokoCam pokoCam;
  48. private FaceCam faceCam;
  49. private Controller controller;
  50. private static Settings settings;
  51. private int windowId;
  52. private IEnumerable<AudioSource> _playingSE;
  53. private HideScroll _hideScroll;
  54. private GameObject configPanel;
  55. private GameObject resultPanel;
  56. private WfScreenChildren screenChildren;
  57. private readonly BindingFlags bindingFlags =
  58. BindingFlags.GetField | BindingFlags.NonPublic |
  59. BindingFlags.DeclaredOnly | BindingFlags.Instance;
  60. private IInitializable[] _initializables;
  61. private MessageBox _msgbox;
  62. private static bool _debug;
  63. #endregion
  64. #region MonoBehavior
  65. private void Awake()
  66. {
  67. DontDestroyOnLoad(this);
  68. }
  69. private void Start()
  70. {
  71. currentGameVer = new Version(GameUty.GetBuildVersionText());
  72. if (pluginGameVer > currentGameVer)
  73. {
  74. enabled = false;
  75. return;
  76. }
  77. Initialize();
  78. SceneManager.sceneLoaded += (scene, mode) =>
  79. {
  80. foreach (var flipAnim in flipAnims)
  81. flipAnim.Load();
  82. settings = Settings.Load();
  83. isStudioMode = scene.name.Contains("ScenePhotoMode");
  84. };
  85. SceneManager.sceneUnloaded += scene =>
  86. {
  87. AllReset();
  88. controller.showController = false;
  89. Settings.Save();
  90. };
  91. }
  92. private void Update()
  93. {
  94. if (isStudioMode)
  95. return;
  96. if (Input.anyKey)
  97. CheckInput();
  98. if (!settings.enablePlugin)
  99. return;
  100. mediator.FindTarget(current);
  101. script.Parse(mediator);
  102. if (!mediator.TargetMaid.IsValid() || !current.isPlay)
  103. return;
  104. mediator.PrepareMuffs();
  105. mediator.PreparePokos(current);
  106. if (mediator.muffsPrepared && mediator.pokosPrepared)
  107. {
  108. mediator.ValidatePair(current);
  109. mediator.UpdateValues(current);
  110. switch (Time.frameCount % 30)
  111. {
  112. case 0:
  113. current.showSkillSelect = IsShowHideScrolls(NameSkillSel);
  114. break;
  115. case 10:
  116. current.showParameter = IsShowHideScrolls(NameParamView);
  117. break;
  118. case 15:
  119. current.showResultPanel = IsShowResultPanel();
  120. break;
  121. case 20:
  122. current.showConfigPanel = IsShowConfigPanel();
  123. break;
  124. }
  125. if (mediator.manLength > 0)
  126. current.isShooting = IsShooting();
  127. current.CanDrawOverlay = true;
  128. }
  129. if (Time.frameCount % 20 == 5)
  130. CheckScreenFade();
  131. if (settings.enablePlugin && mediator.TargetMan.IsValid())
  132. {
  133. var smr = mediator.TargetMan.GetComponentsInChildren<SkinnedMeshRenderer>().FirstOrDefault(s => s.name.Equals("karada", StringComparison.InvariantCultureIgnoreCase));
  134. if (smr == null)
  135. return;
  136. var mat = smr.materials[1];
  137. if (origShader == null)
  138. origShader = mat.shader;
  139. if (!current.isPlay || (mat.shader.name == "CM3D2/Man" && !settings.OnGUI_HidePenis))
  140. mat.shader = origShader;
  141. else if (mat.shader.name == origShader.name && settings.OnGUI_HidePenis)
  142. {
  143. mat.shader = manShader;
  144. mat.SetFloat("_FloatValue2", 0f);
  145. mat.renderQueue = 3500;
  146. }
  147. }
  148. }
  149. private Shader manShader = Shader.Find("CM3D2/Man");
  150. private Shader origShader;
  151. private void LateUpdate()
  152. {
  153. if (current.CanDrawOverlay)
  154. DrawOverlay();
  155. current.CanDrawOverlay = false;
  156. if (!_debug)
  157. return;
  158. if (_msgbox == null)
  159. {
  160. _msgbox = new MessageBox();
  161. FindObjectOfType<SystemInfoHUD>().enabled = true;
  162. return;
  163. }
  164. foreach (var poko in mediator.pokos)
  165. poko?.DrawTrails();
  166. }
  167. private void OnGUI()
  168. {
  169. if (isStudioMode)
  170. return;
  171. if (controller.showController)
  172. controller.Draw();
  173. if (settings.enablePlugin && mediator.TargetMaid.IsValid() && current.isPlay)
  174. {
  175. DrawFlipAnims();
  176. DrawPokoCam();
  177. DrawFaceCam();
  178. }
  179. if (_debug)
  180. {
  181. _msgbox?.Draw(
  182. new GUIContent(
  183. $"maid:{script.MaidAnmName}\n" +
  184. $"man0:{script.ManAnmName}\n" +
  185. $"currentSkill:{current.CurrentSkill}\n" +
  186. $"prim:{current.PrimaryMuff.ToString()}\n" +
  187. $"mode:{current.PlayMode.ToString()}\n" +
  188. $"num:{current.MuffNum.ToString()}\n" +
  189. $"stat:{current.PlayState}\n" +
  190. $"play:{current.isPlay} onani:{current.isOnani}\n" +
  191. $"pokotype:{current.PokoType} \n" +
  192. $"poko[0]:{mediator.pokos[0]?.TargetMuff}\n" +
  193. $"poko[1]:{mediator.pokos[1]?.TargetMuff}\n" +
  194. $"poko[2]:{mediator.pokos[2]?.TargetMuff}\n" +
  195. $"skillSel:{current.showSkillSelect} " +
  196. $"paramVew:{current.showParameter} " +
  197. $"confPanel:{current.showConfigPanel}" +
  198. $"resPanel:{current.showResultPanel}" +
  199. $"isShot:{current.isShooting}"
  200. )
  201. );
  202. }
  203. }
  204. #endregion
  205. #region Methods
  206. private void Initialize()
  207. {
  208. mediator = new Mediator();
  209. current = new State();
  210. script = new AnmScript(current);
  211. pokoCam = new PokoCam();
  212. faceCam = new FaceCam();
  213. windowId = PluginName.ToCharArray().Sum(x => x) * PluginVersion.ToCharArray().Sum(x => x);
  214. var dirInfoInjector = new DirectoryInfo($@"{Assembly.GetExecutingAssembly().Location}").Parent;
  215. var dirInfoConfig = new DirectoryInfo($@"{dirInfoInjector}\Config\{PathConfig}");
  216. settings = Settings.Load(new FileInfo($@"{dirInfoConfig}\{FileNameConfig}"));
  217. var pathTexSrcFront = new DirectoryInfo($@"{dirInfoConfig}\v");
  218. var pathTexSrcBack = new DirectoryInfo($@"{dirInfoConfig}\a");
  219. var pathTexSrcMouth = new DirectoryInfo($@"{dirInfoConfig}\o");
  220. flipAnims = new[]
  221. {
  222. new FlipAnim(pathTexSrcFront),
  223. new FlipAnim(pathTexSrcBack),
  224. new FlipAnim(pathTexSrcMouth)
  225. };
  226. _initializables = new IInitializable[]
  227. {
  228. mediator, current, script, pokoCam, faceCam, flipAnims[0], flipAnims[1], flipAnims[2]
  229. };
  230. controller = new Controller(this);
  231. }
  232. private void DrawFlipAnims()
  233. {
  234. for (var i = 0; i < 3; i++)
  235. {
  236. if ((current.PokoType == PokoType.Finger || current.PokoType == PokoType.Tongue) && i < 2)
  237. continue;
  238. flipAnims[i].Draw(i, current);
  239. }
  240. }
  241. private void DrawPokoCam()
  242. {
  243. if (settings.enablePokoCam && mediator.manLength > 0)
  244. {
  245. if (pokoCam.SetupCam(mediator.TargetMaid, mediator.TargetMan, current.PrimaryMuff))
  246. {
  247. var n = (int)current.PrimaryMuff;
  248. if (n > 2) n = 2;
  249. if (flipAnims[n] != null || mediator.muffs[n] != null)
  250. {
  251. pokoCam.Action();
  252. //var rect = settings.PokoCam_CustomPos && settings.PokoCam_Pos.size != Vector2.zero
  253. // ? settings.PokoCam_Pos
  254. // : settings.PokoCam_Pos = flipAnims[n].CalcRect(3, current.showParameter);
  255. var rect = FlipAnim.ScreenRect.Get(3, current.showParameter);
  256. pokoCam.Draw(current, rect);
  257. }
  258. }
  259. }
  260. else { pokoCam.Initialize(); }
  261. }
  262. private void DrawFaceCam()
  263. {
  264. if (settings.enableFaceCam && faceCam.SetupCam(mediator.TargetMaid))
  265. {
  266. faceCam.Action();
  267. faceCam.Draw(current, FlipAnim.ScreenRect.Get(2, current.showParameter));
  268. }
  269. }
  270. private void DrawOverlay()
  271. {
  272. for (var i = 0; i < 3; i++)
  273. {
  274. if (!current.isPlay || current.PokoType == PokoType.Finger || current.PokoType == PokoType.Tongue)
  275. {
  276. flipAnims[i].Overlay.Stop();
  277. return;
  278. }
  279. flipAnims[i].Overlay.Draw(mediator.muffs[i].GetOverlayPos(), i, current);
  280. }
  281. }
  282. private void CheckInput()
  283. {
  284. if (Input.GetKeyDown(settings.ControllerHotKey))
  285. controller.showController = !controller.showController;
  286. if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftShift)
  287. && Input.GetKeyDown(settings.ControllerHotKey))
  288. _debug = !_debug;
  289. //if (!settings.enablePlugin)
  290. // return;
  291. //
  292. //if (controller.showController && settings.enablePokoCam && settings.PokoCam_CustomPos)
  293. //{
  294. // if (Input.GetKey(KeyCode.Mouse0))
  295. // {
  296. // if (settings.PokoCam_Pos.Contains(Event.current.mousePosition))
  297. // {
  298. // settings.PokoCam_Pos.center =
  299. // Vector2.Lerp(settings.PokoCam_Pos.center, Event.current.mousePosition, 0.25f);
  300. // }
  301. // }
  302. //}
  303. }
  304. private bool IsShooting()
  305. {
  306. if (!current.shotReady)
  307. return false;
  308. _playingSE = FindObjectsOfType<AudioSource>()?.Where(x => x.isPlaying);
  309. if (_playingSE == null)
  310. return false;
  311. var count = 0;
  312. foreach (var se in _playingSE)
  313. {
  314. if (se == null)
  315. continue;
  316. if (se.clip.name.Contains(SE_CumShot))
  317. {
  318. if (current.PlayMode == PlayMode.Multiple)
  319. return true;
  320. count++;
  321. }
  322. }
  323. return count == 1;
  324. }
  325. private bool IsShowHideScrolls(string hideName)
  326. {
  327. if (_hideScroll == null)
  328. {
  329. foreach (var x in FindObjectsOfType<HideScroll>().Where(x => x.isActiveAndEnabled))
  330. {
  331. if (x.name == "Top" && x.ParentObject.name == hideName)
  332. {
  333. _hideScroll = x;
  334. break;
  335. }
  336. }
  337. return false;
  338. }
  339. if (_hideScroll.ParentObject.name != hideName)
  340. return false;
  341. return (bool)(_hideScroll.GetType().GetField(NameHideScrollField, bindingFlags)?.GetValue(_hideScroll) ?? false);
  342. }
  343. private bool IsShowConfigPanel()
  344. {
  345. if (configPanel != null)
  346. return configPanel.activeInHierarchy;
  347. configPanel = GameObject.Find(ConfigPanel);
  348. return false;
  349. }
  350. private bool IsShowResultPanel()
  351. {
  352. if (resultPanel != null)
  353. return resultPanel.activeInHierarchy;
  354. resultPanel = GameObject.Find(ResultPanel);
  355. return false;
  356. }
  357. private void CheckScreenFade()
  358. {
  359. if (screenChildren)
  360. {
  361. if (screenChildren.fade_status != WfScreenChildren.FadeStatus.Null)
  362. {
  363. if (screenChildren.fade_status != WfScreenChildren.FadeStatus.Wait)
  364. {
  365. mediator.Initialize();
  366. script.Initialize();
  367. }
  368. return;
  369. }
  370. screenChildren = null;
  371. }
  372. foreach (var children in FindObjectsOfType<WfScreenChildren>())
  373. {
  374. if (children && children.fade_status != WfScreenChildren.FadeStatus.Null)
  375. {
  376. screenChildren = children;
  377. return;
  378. }
  379. }
  380. if (GameMain.Instance.MainCamera.IsFadeOut())
  381. {
  382. mediator.Initialize();
  383. script.Initialize();
  384. }
  385. }
  386. private static void DestroyPluginObjects()
  387. {
  388. var objects = FindObjectsOfType<GameObject>();
  389. foreach (var obj in objects)
  390. if (obj.name.Contains($"{PluginName}"))
  391. DestroyObject(obj);
  392. }
  393. private void AllReset()
  394. {
  395. foreach (var ini in _initializables)
  396. ini?.Initialize();
  397. DestroyPluginObjects();
  398. }
  399. #endregion
  400. #region Classes
  401. private class Mediator : IInitializable
  402. {
  403. private bool initialized;
  404. private CharacterMgr charaMgr;
  405. private Maid[] manArray;
  406. public int manLength;
  407. public Maid TargetMaid;
  408. public Maid TargetMan;
  409. internal Muff[] muffs;
  410. internal Poko[] pokos;
  411. public bool muffsPrepared;
  412. public bool pokosPrepared;
  413. private Vector3 maidOffset;
  414. public bool SwapTargetNPC;
  415. public Mediator()
  416. {
  417. charaMgr = GameMain.Instance.CharacterMgr;
  418. manArray = new Maid[charaMgr.GetManCount()];
  419. muffs = new Muff[3];
  420. pokos = new Poko[charaMgr.GetManCount()];
  421. Initialize();
  422. }
  423. public void Initialize()
  424. {
  425. if (initialized)
  426. return;
  427. Array.Clear(manArray, 0, manArray.Length);
  428. Array.Clear(pokos, 0, pokos.Length);
  429. TargetMaid = null;
  430. TargetMan = null;
  431. manLength = 0;
  432. muffsPrepared = false;
  433. pokosPrepared = false;
  434. initialized = true;
  435. }
  436. public void FindTarget(State current)
  437. {
  438. if (charaMgr.IsBusy())
  439. return;
  440. if (current.PlayMode != PlayMode.Swap || !charaMgr.GetMaid(1).IsValid())
  441. SwapTargetNPC = false;
  442. var maid = current.PlayMode == PlayMode.Harem || SwapTargetNPC
  443. ? charaMgr.GetMaid(1)
  444. : charaMgr.GetMaid(0);
  445. if (maid == null)
  446. {
  447. if (TargetMaid.IsValid())
  448. {
  449. Initialize();
  450. current.Initialize();
  451. }
  452. return;
  453. }
  454. TargetMaid = maid;
  455. manLength = 0;
  456. for (var i = 0; i < manArray.Length; i++)
  457. {
  458. var man = charaMgr.GetMan(i);
  459. if (man.IsValid() && man.body0.GetChinkoVisible())
  460. {
  461. manArray[i] = man;
  462. manLength++;
  463. }
  464. }
  465. TargetMan = current.PlayMode == PlayMode.Swap && manArray[1] != null && !SwapTargetNPC
  466. ? manArray[1]
  467. : manArray[0];
  468. initialized = false;
  469. }
  470. public void PrepareMuffs()
  471. {
  472. if (muffsPrepared)
  473. return;
  474. if (!TargetMaid.IsValid())
  475. {
  476. muffsPrepared = false;
  477. return;
  478. }
  479. if (muffs[0] == null || !maidOffset.Equals(TargetMaid.body0.CenterBone.position))
  480. {
  481. muffs[0] = new Front(MuffType.Front, TargetMaid);
  482. muffs[1] = new Back(MuffType.Back, TargetMaid);
  483. muffs[2] = new Mouth(MuffType.Mouth, TargetMaid);
  484. maidOffset = TargetMaid.body0.CenterBone.position;
  485. }
  486. else
  487. {
  488. muffs[0].Set(MuffType.Front, TargetMaid);
  489. muffs[1].Set(MuffType.Back, TargetMaid);
  490. muffs[2].Set(MuffType.Mouth, TargetMaid);
  491. }
  492. muffsPrepared = muffs[0].Maid == TargetMaid;
  493. }
  494. public void PreparePokos(State current)
  495. {
  496. if (pokosPrepared || !muffsPrepared)
  497. return;
  498. switch (current.PlayMode)
  499. {
  500. case PlayMode.Self:
  501. for (int i = 0; i < pokos.Length; i++)
  502. {
  503. if (pokos[i]?.GetType() == typeof(TNP))
  504. pokos[i] = null;
  505. }
  506. break;
  507. case PlayMode.Normal:
  508. case PlayMode.Swap:
  509. case PlayMode.Harem:
  510. if (TargetMan == null)
  511. {
  512. pokosPrepared = false;
  513. return;
  514. }
  515. if (!(pokos[0] is TNP t) || !t.man.IsValid())
  516. pokos[0] = new TNP(TargetMan);
  517. break;
  518. case PlayMode.Multiple:
  519. for (var i = 0; i < pokos.Length; i++)
  520. {
  521. if (manArray[i] == null)
  522. break;
  523. if (!(pokos[i] is TNP g) || !g.man.IsValid())
  524. pokos[i] = new TNP(manArray[i]);
  525. }
  526. pokosPrepared = pokos[manLength > 1 ? manLength - 1 : 0] != null;
  527. return;
  528. }
  529. if (current.PokoType == PokoType.TNP)
  530. {
  531. pokosPrepared = pokos[0] != null;
  532. return;
  533. }
  534. var last = pokos.Length - 1;
  535. switch (current.PokoType)
  536. {
  537. case PokoType.Tongue:
  538. if (TargetMan.IsValid())
  539. {
  540. if (!(pokos[last] is Tongue t) || !t.man.IsValid())
  541. pokos[last] = new Tongue(TargetMan);
  542. }
  543. pokosPrepared = pokos[last] is Tongue tt && tt.man.IsValid();
  544. break;
  545. case PokoType.Dildo:
  546. if (TargetMaid.IsValid())
  547. {
  548. if (!(pokos[last] is Dildo d) || !d.maid.IsValid())
  549. pokos[last] = new Dildo(TargetMaid);
  550. }
  551. pokosPrepared = pokos[last] is Dildo dd && dd.maid.IsValid();
  552. break;
  553. case PokoType.Vibe:
  554. if (!(pokos[last] is Vibe))
  555. pokos[last] = new Vibe();
  556. pokosPrepared = true;
  557. break;
  558. case PokoType.Finger:
  559. var m = current.isOnani ? TargetMaid : TargetMan;
  560. if (!(pokos[last - 1] is Finger f) || !f.maid.IsValid() || f.maid != m)
  561. {
  562. pokos[last - 1] = new Finger(m, true);
  563. pokos[last] = new Finger(m, false);
  564. }
  565. pokosPrepared = pokos[last - 1] is Finger;
  566. break;
  567. }
  568. }
  569. public void ValidatePair(State current)
  570. {
  571. if (current.PrimaryMuff == MuffType.None)
  572. return;
  573. switch (current.PlayMode)
  574. {
  575. case PlayMode.Self:
  576. foreach (var poko in pokos)
  577. {
  578. if (poko?.ValidateTargetMuff(muffs[(int)current.PrimaryMuff]) ?? false)
  579. return;
  580. }
  581. pokosPrepared = false;
  582. return;
  583. case PlayMode.Normal:
  584. case PlayMode.Swap:
  585. case PlayMode.Harem:
  586. var n = (int)current.PrimaryMuff == 1 ? 1 : 0;
  587. switch (current.PokoType)
  588. {
  589. case PokoType.Finger:
  590. foreach (var poko in pokos)
  591. {
  592. if (poko is Finger f && f.ValidateTargetMuff(muffs[n]))
  593. return;
  594. }
  595. break;
  596. case PokoType.Vibe:
  597. foreach (var poko in pokos)
  598. {
  599. if (poko is Vibe v && v.ValidateTargetMuff(muffs[n]))
  600. return;
  601. }
  602. break;
  603. case PokoType.Tongue:
  604. foreach (var poko in pokos)
  605. {
  606. if (poko is Tongue t && t.ValidateTargetMuff(muffs[0]))
  607. return;
  608. }
  609. break;
  610. case PokoType.TNP:
  611. if (pokos[0] is TNP p && p.ValidateTargetMuff(muffs[(int)current.PrimaryMuff]))
  612. return;
  613. break;
  614. }
  615. pokosPrepared = false;
  616. return;
  617. case PlayMode.Multiple:
  618. pokos[0]?.ValidateTargetMuff(muffs[(int)current.PrimaryMuff]);
  619. switch (current.MuffNum)
  620. {
  621. case MuffNum.Double:
  622. pokos[1]?.ValidateTargetMuff(muffs[1 - (int)current.PrimaryMuff]);
  623. return;
  624. case MuffNum.Triple:
  625. case MuffNum.Unknown:
  626. for (var i = 1; i < manLength; i++)
  627. {
  628. if (pokos[i] == null)
  629. continue;
  630. for (var j = 2; j >= 0; j--)
  631. {
  632. if (j == (int)current.PrimaryMuff)
  633. continue;
  634. if (pokos[i].ValidateTargetMuff(muffs[j]))
  635. break;
  636. }
  637. }
  638. break;
  639. }
  640. break;
  641. }
  642. }
  643. public void UpdateValues(State current)
  644. {
  645. for (var i = 0; i < muffs.Length; i++)
  646. {
  647. var value = 0.0f;
  648. foreach (var poko in pokos)
  649. {
  650. if (poko == null || !poko.Validated)
  651. continue;
  652. if ((int)poko.TargetMuff == i)
  653. {
  654. var _v = muffs[i].GetInsertRate(current, poko);
  655. value = _v > value ? _v : value;
  656. var n = (int)current.PrimaryMuff == 1 ? 1 : 0;
  657. if ((current.PokoType == PokoType.Finger || current.PokoType == PokoType.Tongue)
  658. && i == n && value > 0.01f)
  659. value = settings.Morpher_Threshold * 0.5f;
  660. }
  661. }
  662. current.rates[i] = Mathf.SmoothStep(current.rates[i], value, settings.Anim_Speed);
  663. muffs[i].SetBlendValue(current.rates[i]);
  664. }
  665. }
  666. }
  667. public class State : IInitializable
  668. {
  669. private string _recent;
  670. public string CurrentSkill
  671. {
  672. get => _recent;
  673. set
  674. {
  675. if (_recent != value)
  676. Initialize();
  677. _recent = value;
  678. }
  679. }
  680. public bool isPlay;
  681. public bool isOnani;
  682. internal MuffNum MuffNum;
  683. internal PlayMode PlayMode;
  684. internal PlayState PlayState;
  685. internal MuffType PrimaryMuff;
  686. internal PokoType PokoType;
  687. internal InsertRates rates = new InsertRates();
  688. public bool isShooting, showSkillSelect, showParameter, showConfigPanel, showResultPanel, CanDrawOverlay;
  689. public bool shotReady => PlayState == PlayState.Shot || PlayState == PlayState.ShotFin;
  690. public State() { Initialize(); }
  691. public void Initialize()
  692. {
  693. isPlay = false;
  694. isOnani = false;
  695. isShooting = false;
  696. showSkillSelect = false;
  697. showParameter = false;
  698. CanDrawOverlay = false;
  699. PlayMode = PlayMode.Normal;
  700. MuffNum = MuffNum.Unknown;
  701. PlayState = PlayState.None;
  702. PrimaryMuff = MuffType.None;
  703. PokoType = PokoType.TNP;
  704. rates.Clear();
  705. }
  706. }
  707. public class InsertRates
  708. {
  709. private float[] rate;
  710. public InsertRates() => rate = new float[3];
  711. public float this[int i]
  712. {
  713. get => rate[i];
  714. set => rate[i] = value > 0.001f ? value : 0.0f;
  715. }
  716. public void Clear() => Array.Clear(rate, 0, 3);
  717. }
  718. private class AnmScript : IInitializable
  719. {
  720. private State _current;
  721. public string MaidAnmName, ManAnmName;
  722. private static readonly string[] ValidSkillNames =
  723. {
  724. "seijyou", "kouhai", "sokui", "kijyoui", "[th]aimenzai", "ritui", "manguri", "hekimen", "tinguri",
  725. "ekiben", "turusi", "matuba", "syumoku", "mzi", "kakae", "tekoki", "tekoona", "fera", "sixnine", "self_ir", "housi",
  726. "onani", "paizuri", "aibu", "kunni", "mp_arai", "arai2", "kousoku", "vibe", "mokuba", "harituke",
  727. "ran\\dp", "muri.*\\dp", ".*\\dp_", "sex"
  728. };
  729. private static readonly Regex PatternValidSkillNames =
  730. new Regex($@"{string.Join("|", ValidSkillNames)}", RegexOptions.Compiled);
  731. private readonly Regex Separator = new Regex(@"_taiki|_in|_ONCE|_once|_shaseigo|_tanetukego|_zeccyougo|_sissin|_\d[^p]", RegexOptions.Compiled);
  732. private readonly Regex patternMultiple = new Regex(@"(ran|muri|kousoku).*\dp", RegexOptions.Compiled);
  733. private readonly Regex patternMuffMouth = new Regex(@"fera|sixnine|self_ir|_kuti|housi", RegexOptions.Compiled);
  734. private readonly Regex patternNoneOutside = new Regex(@"^.*(_soto|_kao).*$", RegexOptions.Compiled);
  735. private readonly Regex patternNoneBreak = new Regex(@"name|suri|koki|tama|sumata", RegexOptions.Compiled);
  736. private readonly Regex patternPlaying = new Regex(@"^.*_\d([ab]0[12])?_|_gr|_momi", RegexOptions.Compiled);
  737. private const string C_ = "C_", A_ = "A_", A = "A";
  738. private const string _2ana = "2ana", _3ana = "3ana";
  739. private const string kunni = "kunni", dildo = "dildo", vibe = "vibe", aibu = "aibu", onani = "onani", _tubo = "_tubo";
  740. private const string _in = "_in", _taiki = "_taiki";
  741. private const string _ONCE = "_ONCE", _once = "_once", _shaseigo = "_shaseigo", _zeccyougo = "_zeccyougo", _tanetukego = "_tanetukego";
  742. private const string seijyou = "seijyou", taimen = "taimen", kouhai = "kouhai", haimen = "haimen", sokui = "sokui";
  743. public AnmScript(State current)
  744. {
  745. _current = current;
  746. Initialize();
  747. }
  748. public void Initialize()
  749. {
  750. _current.Initialize();
  751. }
  752. public void Parse(Mediator med)
  753. {
  754. if (!med.TargetMaid.IsValid())
  755. return;
  756. MaidAnmName = med.TargetMaid.body0.LastAnimeFN;
  757. ManAnmName = med.manLength > 0
  758. ? med.TargetMan.body0.LastAnimeFN
  759. : "";
  760. if (!PatternValidSkillNames.IsMatch(MaidAnmName))
  761. {
  762. if (_current.isPlay)
  763. {
  764. _current.Initialize();
  765. med.Initialize();
  766. DestroyPluginObjects();
  767. }
  768. _current.CurrentSkill = null;
  769. return;
  770. }
  771. _current.isPlay = true;
  772. _current.CurrentSkill = ParseCurrentSkill();
  773. var muff = _current.PrimaryMuff;
  774. var poko = _current.PokoType;
  775. var ona = _current.isOnani;
  776. if (!string.IsNullOrEmpty(_current.CurrentSkill))
  777. {
  778. _current.PlayMode = ParsePlayMode();
  779. _current.PrimaryMuff = ParsePrimary();
  780. _current.MuffNum = ParseMuffNum();
  781. }
  782. _current.isOnani = MaidAnmName.Contains(onani);
  783. _current.PokoType = ParsePokoType();
  784. _current.PlayState = ParsePlayState();
  785. if (muff != _current.PrimaryMuff || poko != _current.PokoType || ona != _current.isOnani)
  786. med.Initialize();
  787. return;
  788. string ParseCurrentSkill()
  789. {
  790. if (!string.IsNullOrEmpty(_current.CurrentSkill) && MaidAnmName.Contains(_current.CurrentSkill))
  791. return _current.CurrentSkill;
  792. if (Separator.IsMatch(MaidAnmName))
  793. return Separator.Split(MaidAnmName)[0];
  794. return "";
  795. }
  796. PlayMode ParsePlayMode()
  797. {
  798. if (MaidAnmName.Contains(C_) || ManAnmName.Contains(C_))
  799. return PlayMode.Harem;
  800. if (patternMultiple.IsMatch(_current.CurrentSkill))
  801. return PlayMode.Multiple;
  802. switch (med.manLength)
  803. {
  804. case 0: return PlayMode.Self;
  805. case 2: return PlayMode.Swap;
  806. default: return PlayMode.Normal;
  807. }
  808. }
  809. MuffType ParsePrimary()
  810. {
  811. if (_current.PlayMode != PlayMode.Multiple && patternMuffMouth.IsMatch(MaidAnmName))
  812. return MuffType.Mouth;
  813. if (_current.CurrentSkill.Contains(A) || MaidAnmName.Contains(A_) || ManAnmName.Contains(A_))
  814. return MuffType.Back;
  815. return MuffType.Front;
  816. }
  817. MuffNum ParseMuffNum()
  818. {
  819. var str = _current.CurrentSkill;
  820. if (str.Contains(_2ana))
  821. return MuffNum.Double;
  822. if (str.Contains(_3ana))
  823. return MuffNum.Triple;
  824. return MuffNum.Unknown;
  825. }
  826. PokoType ParsePokoType()
  827. {
  828. switch (MaidAnmName)
  829. {
  830. case string s when s.Contains(kunni):
  831. return PokoType.Tongue;
  832. case string s when s.Contains(dildo):
  833. return PokoType.Dildo;
  834. case string s when s.Contains(vibe):
  835. return PokoType.Vibe;
  836. case string s when s.Contains(aibu) || s.Contains(onani) || s.Contains(_tubo):
  837. return PokoType.Finger;
  838. default:
  839. return PokoType.TNP;
  840. }
  841. }
  842. PlayState ParsePlayState()
  843. {
  844. if (MaidAnmName.Contains(_in))
  845. {
  846. if (_current.PlayState != PlayState.Insert)
  847. med.Initialize();
  848. return PlayState.Insert;
  849. }
  850. if (MaidAnmName.Contains(_taiki))
  851. return PlayState.Wait;
  852. if (patternNoneBreak.IsMatch(MaidAnmName) || patternNoneOutside.IsMatch(ManAnmName))
  853. return PlayState.Eject;
  854. if (MaidAnmName.Contains(_ONCE) || MaidAnmName.Contains(_once))
  855. return PlayState.Shot;
  856. if (MaidAnmName.Contains(_shaseigo) || MaidAnmName.Contains(_tanetukego)
  857. || MaidAnmName.Contains(_zeccyougo))
  858. return PlayState.ShotFin;
  859. if (patternPlaying.IsMatch(MaidAnmName))
  860. return PlayState.Play;
  861. return PlayState.None;
  862. }
  863. }
  864. internal sPosition GetsPosition(MuffType muffType)
  865. {
  866. if (_current.PlayMode != PlayMode.Self)
  867. if (muffType == MuffType.Front || muffType == MuffType.Back)
  868. {
  869. if (MaidAnmName.Contains(seijyou) || MaidAnmName.Contains(taimen))
  870. return sPosition.Normal;
  871. if (MaidAnmName.Contains(kouhai) || MaidAnmName.Contains(haimen))
  872. return sPosition.Dog;
  873. if (MaidAnmName.Contains(sokui))
  874. return sPosition.Side;
  875. }
  876. return sPosition.None;
  877. }
  878. }
  879. #region Muffs
  880. private class Front : Muff
  881. {
  882. internal Front(MuffType type, Maid maid)
  883. {
  884. Set(type, maid);
  885. }
  886. internal override void Set(MuffType type, Maid maid)
  887. {
  888. colliderSize = 1.0f;
  889. this.type = type;
  890. Maid = maid;
  891. body = Maid.body0;
  892. if (collider == null)
  893. collider = new MuffCollider(this.type);
  894. else
  895. collider.Set(this.type);
  896. if (morpher == null)
  897. morpher = new MuffMorpher(this.type, body);
  898. else
  899. morpher.Set(this.type, body);
  900. positions = new Positions();
  901. }
  902. protected override void CheckTransforms()
  903. {
  904. if (!_root)
  905. _root = body.Spine
  906. ? body.Spine
  907. : body.IKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Spine0);
  908. if (!_mid)
  909. _mid = body.Pelvis
  910. ? body.Pelvis
  911. : body.IKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Pelvis);
  912. if (!_top)
  913. _top = body.GetBone(VaginaBoneName);
  914. if (!_other)
  915. _other = body.GetBone(AnalBoneName);
  916. }
  917. public override Positions GetOverlayPos()
  918. {
  919. var cameraMain = GameMain.Instance.MainCamera;
  920. Update();
  921. var start = _top.position;
  922. var end = _root.position - (_other.position - _top.position) * 0.5f;
  923. var dir = start - end;
  924. start -= (start - cameraMain.GetPos()) * settings.Overlay_CameraDistance;
  925. end = end - (dir * settings.Overlay_LineScale)
  926. - (end - cameraMain.GetPos()) * settings.Overlay_CameraDistance;
  927. start += dir.normalized * settings.Overlay_DirectionalOffset;
  928. end += dir.normalized * settings.Overlay_DirectionalOffset;
  929. positions.Top = start;
  930. positions.Root = end;
  931. return positions;
  932. }
  933. public override float GetInsertRate(State current, Poko poko)
  934. {
  935. if (current.PlayState == PlayState.Wait || current.PlayState == PlayState.None)
  936. return 0.0f;
  937. Update();
  938. var pos = poko.GetPokoPos();
  939. var dstTop2mid = Distance(pos.Top, _mid.position);
  940. var tnkLength = Distance(pos.Root, pos.Top);
  941. if (__length < 0.001f)
  942. __length = Mathf.Sqrt(tnkLength);
  943. var dstRoot2top = Distance(pos.Root, _top.position);
  944. var muffDepth = Distance(_top.position, _root.position);
  945. if (tnkLength >= dstRoot2top && muffDepth >= dstTop2mid)
  946. {
  947. if (poko._lastTime > Time.frameCount)
  948. return Mathf.InverseLerp(__length, 0, Mathf.Sqrt(dstRoot2top));
  949. if (collider.ContainsAny(pos))
  950. {
  951. poko._lastTime = Time.frameCount + 5;
  952. return Mathf.InverseLerp(__length, 0, Mathf.Sqrt(dstRoot2top));
  953. }
  954. }
  955. return 0.0f;
  956. }
  957. }
  958. private class Back : Muff
  959. {
  960. internal Back(MuffType type, Maid maid)
  961. {
  962. Set(type, maid);
  963. }
  964. internal override void Set(MuffType type, Maid maid)
  965. {
  966. colliderSize = 1.0f;
  967. this.type = type;
  968. Maid = maid;
  969. body = Maid.body0;
  970. if (collider == null)
  971. collider = new MuffCollider(this.type);
  972. else
  973. collider.Set(this.type);
  974. if (morpher == null)
  975. morpher = new MuffMorpher(this.type, body);
  976. else
  977. morpher.Set(this.type, body);
  978. positions = new Positions();
  979. }
  980. protected override void CheckTransforms()
  981. {
  982. if (!_root)
  983. _root = body.Spine
  984. ? body.Spine
  985. : body.IKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Spine0);
  986. if (!_mid)
  987. _mid = body.Pelvis
  988. ? body.Pelvis
  989. : body.IKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Pelvis);
  990. if (!_top)
  991. _top = body.GetBone(AnalBoneName);
  992. if (!_other)
  993. _other = body.GetBone(VaginaBoneName);
  994. }
  995. public override Positions GetOverlayPos()
  996. {
  997. var cameraMain = GameMain.Instance.MainCamera;
  998. Update();
  999. var start = _top.position;
  1000. var end = _root.position - (_other.position - _top.position) * 0.5f;
  1001. var dir = start - end;
  1002. start = start - (start - cameraMain.GetPos()) * settings.Overlay_CameraDistance;
  1003. end = end - (dir * settings.Overlay_LineScale)
  1004. - (end - cameraMain.GetPos()) * settings.Overlay_CameraDistance;
  1005. start += dir.normalized * settings.Overlay_DirectionalOffset;
  1006. end += dir.normalized * settings.Overlay_DirectionalOffset;
  1007. positions.Top = start;
  1008. positions.Root = end;
  1009. return positions;
  1010. }
  1011. public override float GetInsertRate(State current, Poko poko)
  1012. {
  1013. if (current.PlayState == PlayState.Wait || current.PlayState == PlayState.None)
  1014. return 0.0f;
  1015. Update();
  1016. var pos = poko.GetPokoPos();
  1017. var dstTop2mid = Distance(pos.Top, _mid.position);
  1018. var tnkLength = Distance(pos.Root, pos.Top);
  1019. if (__length < 0.001f)
  1020. __length = Mathf.Sqrt(tnkLength);
  1021. var dstRoot2top = Distance(pos.Root, _top.position);
  1022. var muffDepth = Distance(_top.position, _root.position);
  1023. if (tnkLength >= dstRoot2top && muffDepth >= dstTop2mid)
  1024. {
  1025. if (poko._lastTime > Time.frameCount)
  1026. return Mathf.InverseLerp(__length, 0, Mathf.Sqrt(dstRoot2top));
  1027. if (collider.ContainsAny(pos))
  1028. {
  1029. poko._lastTime = Time.frameCount + 5;
  1030. return Mathf.InverseLerp(__length, 0, Mathf.Sqrt(dstRoot2top));
  1031. }
  1032. }
  1033. return 0.0f;
  1034. }
  1035. }
  1036. private class Mouth : Muff
  1037. {
  1038. internal static readonly Vector3 mouthOffset = new Vector3(0, -0.02f, 0.08f);
  1039. internal Mouth(MuffType type, Maid maid)
  1040. {
  1041. Set(type, maid);
  1042. }
  1043. internal override void Set(MuffType type, Maid maid)
  1044. {
  1045. this.type = type;
  1046. Maid = maid;
  1047. body = Maid.body0;
  1048. if (collider == null)
  1049. collider = new MuffCollider(this.type);
  1050. else
  1051. collider.Set(this.type);
  1052. positions = new Positions();
  1053. colliderSize = 1.75f;
  1054. }
  1055. protected override void CheckTransforms()
  1056. {
  1057. if (_top == null)
  1058. {
  1059. _top = new GameObject($"{PluginName}__mouth__").transform;
  1060. var parent = body.GetBone(MouthBoneName);
  1061. _top.SetParent(parent);
  1062. _top.SetPositionAndRotation(parent.position, parent.rotation);
  1063. _top.Translate(mouthOffset);
  1064. }
  1065. if (_root == null)
  1066. _root = body.trsHead;
  1067. }
  1068. public override Positions GetOverlayPos()
  1069. {
  1070. if (_top == null || _root == null)
  1071. return positions;
  1072. var cameraMain = GameMain.Instance.MainCamera;
  1073. Update();
  1074. var start = _top.position;
  1075. var end = _root.position - (_top.position - _root.position) * 0.5f;
  1076. var dir = start - end;
  1077. start -= (start - cameraMain.GetPos()) * settings.Overlay_CameraDistance;
  1078. end = end - (dir * settings.Overlay_LineScale)
  1079. - (end - cameraMain.GetPos()) * settings.Overlay_CameraDistance;
  1080. start += dir.normalized * settings.Overlay_DirectionalOffset;
  1081. end += dir.normalized * settings.Overlay_DirectionalOffset;
  1082. positions.Top = start;
  1083. positions.Root = end;
  1084. return positions;
  1085. }
  1086. public override float GetInsertRate(State current, Poko poko)
  1087. {
  1088. if (current.PlayState == PlayState.Wait || current.PlayState == PlayState.None)
  1089. return 0.0f;
  1090. Update();
  1091. var pos = poko.GetPokoPos();
  1092. var tnkLength = Distance(pos.Root, pos.Top);
  1093. if (__length < 0.001f)
  1094. __length = Mathf.Sqrt(tnkLength);
  1095. var dstRoot2top = Distance(pos.Root, _top.position);
  1096. if (tnkLength >= dstRoot2top)
  1097. {
  1098. if (poko._lastTime > Time.frameCount)
  1099. return Mathf.InverseLerp(__length, 0, Mathf.Sqrt(dstRoot2top));
  1100. if (collider.ContainsAny(pos))
  1101. {
  1102. poko._lastTime = Time.frameCount + 5;
  1103. return Mathf.InverseLerp(__length, 0, Mathf.Sqrt(dstRoot2top));
  1104. }
  1105. }
  1106. return 0.0f;
  1107. }
  1108. }
  1109. public abstract class Muff
  1110. {
  1111. internal const string VaginaBoneName = "_IK_vagina",
  1112. AnalBoneName = "_IK_anal",
  1113. MouthBoneName = "Mouth";
  1114. public Maid Maid;
  1115. protected TBody body;
  1116. protected Positions positions;
  1117. protected Transform _top, _mid, _root, _other;
  1118. protected MuffCollider collider;
  1119. internal MuffMorpher morpher;
  1120. internal MuffType type;
  1121. private float depth => Vector3.Distance(_top.position, _root.position);
  1122. protected float colliderSize;
  1123. protected float __length;
  1124. protected abstract void CheckTransforms();
  1125. public abstract Positions GetOverlayPos();
  1126. internal abstract void Set(MuffType type, Maid maid);
  1127. public MuffCollider GetCollider()
  1128. {
  1129. Update();
  1130. return collider;
  1131. }
  1132. protected void Update()
  1133. {
  1134. if (!Maid.IsValid())
  1135. return;
  1136. CheckTransforms();
  1137. collider.SetTransform(_top, (_root != null ? _root : _mid), depth * colliderSize);
  1138. }
  1139. public void SetBlendValue(float value)
  1140. {
  1141. if (!settings.enableMorpher)
  1142. return;
  1143. morpher?.SetBlendEx(value);
  1144. if (!settings.Morpher_EnableFix)
  1145. return;
  1146. morpher?.FixBlendEx();
  1147. }
  1148. protected static float Distance(Vector3 from, Vector3 to)
  1149. {
  1150. var xD = from.x - to.x;
  1151. var yD = from.y - to.y;
  1152. var zD = from.z - to.z;
  1153. return xD * xD + yD * yD + zD * zD;
  1154. }
  1155. public abstract float GetInsertRate(State current, Poko poko);
  1156. }
  1157. public class MuffCollider
  1158. {
  1159. private MuffType type;
  1160. private GameObject obj;
  1161. private BoxCollider collider;
  1162. private MeshRenderer renderer;
  1163. private Transform start, end;
  1164. private Vector3 scale;
  1165. private const float distance = 0.55f;
  1166. internal MuffCollider(MuffType type)
  1167. {
  1168. Set(type);
  1169. }
  1170. internal void Set(MuffType type)
  1171. {
  1172. this.type = type;
  1173. }
  1174. public void SetTransform(Transform start, Transform end, float length)
  1175. {
  1176. this.start = start;
  1177. this.end = end;
  1178. scale.Set(length * 0.5f, length * 0.5f, length);
  1179. }
  1180. private bool SetUpCollider()
  1181. {
  1182. if (!start || !end)
  1183. return false;
  1184. if (obj == null)
  1185. {
  1186. obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
  1187. renderer = obj.GetComponent<MeshRenderer>();
  1188. obj.name = $"{PluginName}__muffcol__{type}";
  1189. collider = null;
  1190. }
  1191. else
  1192. {
  1193. if (collider == null)
  1194. {
  1195. collider = obj.GetComponent<BoxCollider>() ?? obj.AddComponent<BoxCollider>();
  1196. collider.isTrigger = true;
  1197. }
  1198. }
  1199. renderer.enabled = _debug;
  1200. return obj && collider;
  1201. }
  1202. public bool Contains(Vector3 point)
  1203. {
  1204. if ((start.position != end.position) && SetUpCollider())
  1205. {
  1206. var rot = Quaternion.LookRotation(start.position - end.position);
  1207. var pos = start.position - (start.position - end.position) * distance;
  1208. collider.transform.SetPositionAndRotation(pos, rot);
  1209. collider.transform.localScale = scale;
  1210. return collider.ClosestPoint(point) == point;
  1211. }
  1212. return false;
  1213. }
  1214. public bool ContainsAny(Positions pos)
  1215. {
  1216. return Contains(pos.Top) || Contains(pos.Mid) || Contains(pos.Root);
  1217. }
  1218. public bool ContainsAny(params Vector3[] points)
  1219. {
  1220. foreach (var p in points)
  1221. if (Contains(p))
  1222. return true;
  1223. return false;
  1224. }
  1225. ~MuffCollider()
  1226. {
  1227. DestroyObject(collider);
  1228. DestroyObject(renderer);
  1229. DestroyObject(obj);
  1230. }
  1231. }
  1232. internal class MuffMorpher
  1233. {
  1234. private TBody body;
  1235. private MuffType type;
  1236. private HashSet<int> keyAvailableSlot;
  1237. private string lastKey;
  1238. private float lastValue;
  1239. public MuffMorpher(MuffType type, TBody body)
  1240. {
  1241. Set(type, body);
  1242. }
  1243. public void Set(MuffType type, TBody body)
  1244. {
  1245. lastValue = 0.0f;
  1246. if (keyAvailableSlot == null)
  1247. keyAvailableSlot = new HashSet<int>();
  1248. else
  1249. keyAvailableSlot.Clear();
  1250. this.body = body;
  1251. this.type = type;
  1252. CheckKeyAvailable(Key);
  1253. }
  1254. private string Key
  1255. {
  1256. get
  1257. {
  1258. var ret = type == MuffType.Front
  1259. ? settings.Morpher_KeyV
  1260. : settings.Morpher_KeyA;
  1261. if (lastKey != ret)
  1262. CheckKeyAvailable(ret);
  1263. return lastKey = ret;
  1264. }
  1265. }
  1266. private void CheckKeyAvailable(string key)
  1267. {
  1268. keyAvailableSlot.Clear();
  1269. if (body != null)
  1270. for (var i = 0; i < (int)TBody.SlotID.end; i++)
  1271. if (body.goSlot?[i]?.morph is TMorph m && m.hash.ContainsKey(key))
  1272. keyAvailableSlot.Add(i);
  1273. }
  1274. public void SetBlendEx(float value)
  1275. {
  1276. if (!settings.enableMorpher || keyAvailableSlot.Count < 1)
  1277. return;
  1278. var result = Mathf.Clamp(
  1279. Mathf.InverseLerp(0.0f, settings.Morpher_Threshold, value),
  1280. settings.Morpher_Min,
  1281. settings.Morpher_Max
  1282. );
  1283. foreach (var slot in keyAvailableSlot)
  1284. {
  1285. if (body.goSlot[slot]?.morph?.hash[Key] is int idx)
  1286. {
  1287. body.goSlot[slot].morph.SetBlendValues(idx, result);
  1288. lastValue = result;
  1289. }
  1290. else
  1291. {
  1292. CheckKeyAvailable(Key);
  1293. return;
  1294. }
  1295. }
  1296. }
  1297. public void FixBlendEx()
  1298. {
  1299. if (!settings.Morpher_EnableFix || keyAvailableSlot.Count < 1 || type == MuffType.Back)
  1300. return;
  1301. if (Time.frameCount % Mathf.RoundToInt(settings.Morpher_Waitframe) == 0)
  1302. {
  1303. foreach (int i in keyAvailableSlot)
  1304. {
  1305. body.goSlot[i]?.morph?.FixBlendValues();
  1306. }
  1307. }
  1308. }
  1309. }
  1310. #endregion
  1311. #region Pokos
  1312. private class TNP : Poko
  1313. {
  1314. private const string TnpTopName = "chinko_nub",
  1315. TnpMidName = "chinko2",
  1316. TnpRootName = "chinko1";
  1317. public Maid man;
  1318. private Transform tnkTop, tnkMid, tnkRoot;
  1319. public TNP(Maid man)
  1320. {
  1321. this.man = man;
  1322. Validated = false;
  1323. TargetMuff = MuffType.None;
  1324. }
  1325. protected override void UpdateTransforms()
  1326. {
  1327. foreach (var trs in man.body0.GetComponentsInChildren<Transform>())
  1328. {
  1329. if (trs == null)
  1330. continue;
  1331. switch (trs.name)
  1332. {
  1333. case TnpTopName:
  1334. tnkTop = trs;
  1335. break;
  1336. case TnpRootName:
  1337. tnkRoot = trs;
  1338. break;
  1339. case TnpMidName:
  1340. tnkMid = trs;
  1341. break;
  1342. }
  1343. if (tnkTop && tnkRoot && tnkMid)
  1344. {
  1345. positions.Top = tnkTop.position;
  1346. positions.Mid = tnkMid.position;
  1347. positions.Root = tnkRoot.position;
  1348. return;
  1349. }
  1350. }
  1351. }
  1352. }
  1353. private class Dildo : Poko
  1354. {
  1355. private const string DildoName = "ディルド&台";
  1356. private Transform[] _transforms;
  1357. public Maid maid;
  1358. public Dildo(Maid maid)
  1359. {
  1360. this.maid = maid;
  1361. _transforms = new Transform[4];
  1362. Validated = false;
  1363. TargetMuff = MuffType.None;
  1364. }
  1365. protected override void UpdateTransforms()
  1366. {
  1367. if (_transforms[0] == null)
  1368. {
  1369. _transforms[0] = GameObject.Find(DildoName)?.transform;
  1370. if (_transforms[0] != null)
  1371. return;
  1372. foreach (var x in FindObjectsOfType<Transform>())
  1373. {
  1374. if (x == null)
  1375. continue;
  1376. if (x.name.Contains(DildoName))
  1377. {
  1378. _transforms[0] = x;
  1379. break;
  1380. }
  1381. }
  1382. }
  1383. else
  1384. {
  1385. if (!maid.IsValid())
  1386. return;
  1387. if (!_transforms[1])
  1388. for (int i = 1; i < 4; i++)
  1389. {
  1390. if (_transforms[i] != null)
  1391. continue;
  1392. _transforms[i] = new GameObject($"{PluginName}__Dildo_{i}").transform;
  1393. _transforms[i].SetParent(_transforms[i - 1]);
  1394. _transforms[i].Translate(0.0f, 0.13f * i, 0.0f);
  1395. }
  1396. var offset = maid.body0.CenterBone.position;
  1397. positions.Top = _transforms[3].position + offset;
  1398. positions.Mid = _transforms[2].position + offset;
  1399. positions.Root = _transforms[1].position + offset;
  1400. }
  1401. }
  1402. }
  1403. private class Vibe : Poko
  1404. {
  1405. private Transform _transform;
  1406. private const string VibeName = "vibe&cli", AnalVibeName = "analvibe", BigVibeName = "Predator";
  1407. private const float HalfLength = 0.1f;
  1408. protected override void UpdateTransforms()
  1409. {
  1410. if (_transform == null)
  1411. _transform = GameObject.Find(VibeName)?.transform;
  1412. if (_transform == null)
  1413. _transform = GameObject.Find(AnalVibeName)?.transform;
  1414. if (_transform == null)
  1415. _transform = GameObject.Find(BigVibeName)?.transform;
  1416. if (_transform == null)
  1417. return;
  1418. var dir = _transform.right;
  1419. positions.Root = _transform.position;
  1420. positions.Mid = positions.Root + dir * HalfLength;
  1421. positions.Top = positions.Mid + dir * HalfLength;
  1422. }
  1423. }
  1424. private class Tongue : Poko
  1425. {
  1426. public Maid man;
  1427. private Transform[] _transforms;
  1428. private const string HeadTopName = "mheadbone_nub";
  1429. public Tongue(Maid man)
  1430. {
  1431. this.man = man;
  1432. _transforms = new Transform[2];
  1433. Validated = false;
  1434. TargetMuff = MuffType.None;
  1435. }
  1436. protected override void UpdateTransforms()
  1437. {
  1438. if (!man.IsValid())
  1439. return;
  1440. _transforms[0] = man.body0.GetComponentsInChildren<Transform>()
  1441. .FirstOrDefault(x => x.name.Contains(HeadTopName));
  1442. if (_transforms[1] == null)
  1443. {
  1444. _transforms[1] = new GameObject($"{PluginName}__mouth__").transform;
  1445. var parent = man.body0.GetBone(Muff.MouthBoneName);
  1446. _transforms[1].SetParent(parent);
  1447. _transforms[1].SetPositionAndRotation(parent.position, parent.rotation);
  1448. _transforms[1].Translate(Mouth.mouthOffset);
  1449. }
  1450. positions.Top = _transforms[0].position;
  1451. positions.Root = _transforms[1].position;
  1452. }
  1453. }
  1454. private class Finger : Poko
  1455. {
  1456. public Maid maid;
  1457. private bool righthand;
  1458. private Transform[] _transforms;
  1459. public Finger(Maid maid, bool righthand)
  1460. {
  1461. this.maid = maid;
  1462. this.righthand = righthand;
  1463. _transforms = new Transform[4];
  1464. }
  1465. protected override void UpdateTransforms()
  1466. {
  1467. if (!maid.IsValid())
  1468. return;
  1469. if (_transforms[0] == null)
  1470. {
  1471. _transforms[0] = righthand
  1472. ? maid.body0.IKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Hand_R).GetComponentsInChildren<Transform>().FirstOrDefault(x => x.name.Contains("R Finger2"))
  1473. : maid.body0.IKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Hand_L).GetComponentsInChildren<Transform>().FirstOrDefault(x => x.name.Contains("L Finger2"));
  1474. }
  1475. else
  1476. {
  1477. _transforms[1] = GetFirstNonSCLChild(_transforms[0]);
  1478. _transforms[2] = GetFirstNonSCLChild(_transforms[1]);
  1479. _transforms[3] = GetFirstNonSCLChild(_transforms[2]);
  1480. positions.Top = _transforms[3].position;
  1481. positions.Mid = _transforms[2].position;
  1482. positions.Root = _transforms[1].position;
  1483. }
  1484. }
  1485. private Transform GetFirstNonSCLChild(Transform t)
  1486. {
  1487. var count = t.childCount;
  1488. for (var i = 0; i < count; i++)
  1489. {
  1490. var child = t.GetChild(i);
  1491. if (!child.name.Contains("_SCL_"))
  1492. return child;
  1493. }
  1494. return t;
  1495. }
  1496. }
  1497. public abstract class Poko
  1498. {
  1499. protected Positions positions;
  1500. internal MuffType TargetMuff;
  1501. public bool Validated;
  1502. internal int _lastTime;
  1503. protected PokoTrail[] trails;
  1504. protected abstract void UpdateTransforms();
  1505. protected Poko()
  1506. {
  1507. positions = new Positions();
  1508. TargetMuff = MuffType.None;
  1509. }
  1510. public bool ValidateTargetMuff(Muff muff)
  1511. {
  1512. if (Validated)
  1513. return true;
  1514. UpdateTransforms();
  1515. if (muff.GetCollider().ContainsAny(positions))
  1516. {
  1517. TargetMuff = muff.type;
  1518. Validated = true;
  1519. }
  1520. return Validated;
  1521. }
  1522. public Positions GetPokoPos()
  1523. {
  1524. UpdateTransforms();
  1525. return positions;
  1526. }
  1527. public void DrawTrails()
  1528. {
  1529. if (trails == null)
  1530. trails = new[] { new PokoTrail(), new PokoTrail(), new PokoTrail() };
  1531. trails[0].Draw(positions.Top, Color.cyan, Color.blue);
  1532. trails[1].Draw(positions.Mid, Color.magenta, Color.red);
  1533. trails[2].Draw(positions.Root, Color.yellow, Color.green);
  1534. }
  1535. }
  1536. #endregion
  1537. public struct Positions
  1538. {
  1539. public Vector3 Top, Mid, Root;
  1540. }
  1541. public class FlipAnim : IInitializable
  1542. {
  1543. private Texture2D[] textures, texturesEx;
  1544. private DirectoryInfo srcPath, srcPathEx;
  1545. private bool textureLoaded, textureLoadedEx;
  1546. public bool TextureLoaded => textureLoaded;
  1547. public bool TextureLoadedEx => textureLoadedEx;
  1548. private static readonly Regex pattern_searchtex = new Regex(@"^.*\.(bmp|gif|tiff|jpeg|jpg|png)$");
  1549. private const int CumInterval = 200;
  1550. private static readonly Texture2D blacktex = Texture2D.blackTexture;
  1551. public static ScreenRect ScreenRect = new ScreenRect();
  1552. private static Color alpha = new Color(1.0f, 1.0f, 1.0f, 0.0f);
  1553. public int MaxFrame, CurrentFrame;
  1554. public Overlay Overlay;
  1555. private Stopwatch sw;
  1556. public FlipAnim(DirectoryInfo dir)
  1557. {
  1558. textures = new Texture2D[0];
  1559. srcPath = dir;
  1560. textureLoaded = false;
  1561. texturesEx = new Texture2D[0];
  1562. srcPathEx = new DirectoryInfo($@"{srcPath.FullName}\ex");
  1563. textureLoadedEx = false;
  1564. Overlay = new Overlay(this);
  1565. sw = new Stopwatch();
  1566. CheckDirExists();
  1567. Load();
  1568. }
  1569. ~FlipAnim()
  1570. {
  1571. textures = null;
  1572. texturesEx = null;
  1573. srcPath = null;
  1574. srcPathEx = null;
  1575. }
  1576. private bool LoadTextures(DirectoryInfo dir, ref Texture2D[] array)
  1577. {
  1578. var fileInfos = dir.GetFiles("*", SearchOption.TopDirectoryOnly)
  1579. .Where(x => pattern_searchtex.IsMatch(x.Name));
  1580. var infos = fileInfos as FileInfo[] ?? fileInfos.ToArray();
  1581. if (!infos.Any())
  1582. return false;
  1583. array = new Texture2D[infos.Length];
  1584. for (var i = 0; i < infos.Length; i++)
  1585. {
  1586. if (!infos[i].Exists)
  1587. return false;
  1588. var data = File.ReadAllBytes(infos[i].FullName);
  1589. array[i] = new Texture2D(1, 1, TextureFormat.DXT5, true);
  1590. if (array[i].LoadImage(data))
  1591. array[i].Apply();
  1592. }
  1593. return true;
  1594. }
  1595. private void CheckDirExists()
  1596. {
  1597. if (!srcPath.Exists)
  1598. {
  1599. srcPath.Create();
  1600. if (!srcPathEx.Exists)
  1601. srcPathEx.Create();
  1602. }
  1603. }
  1604. public void Load()
  1605. {
  1606. if (srcPath == null)
  1607. return;
  1608. CheckDirExists();
  1609. textureLoaded = LoadTextures(srcPath, ref textures);
  1610. if (srcPathEx == null)
  1611. return;
  1612. textureLoadedEx = LoadTextures(srcPathEx, ref texturesEx);
  1613. Initialize();
  1614. }
  1615. public void Initialize()
  1616. {
  1617. if (!textureLoaded)
  1618. return;
  1619. CurrentFrame = 0;
  1620. ScreenRect.Set(textures[0].width, textures[0].height);
  1621. MaxFrame = textures.Length;
  1622. }
  1623. internal Texture2D GetCurrentTex()
  1624. {
  1625. return !textureLoaded ? blacktex : textures[CurrentFrame];
  1626. }
  1627. internal Texture2D StartCumAnimation(bool shot)
  1628. {
  1629. if (!shot)
  1630. {
  1631. sw.Stop();
  1632. return GetCurrentTex();
  1633. }
  1634. if (!sw.IsRunning)
  1635. {
  1636. sw.Reset();
  1637. sw.Start();
  1638. }
  1639. else
  1640. {
  1641. var max = texturesEx.Length;
  1642. var rateEx = Mathf.InverseLerp(0, CumInterval, sw.ElapsedMilliseconds);
  1643. if (rateEx <= 1.0f)
  1644. {
  1645. if (textureLoadedEx && max > 1)
  1646. return texturesEx[Mathf.RoundToInt((max - 1) * rateEx)];
  1647. }
  1648. else
  1649. sw.Stop();
  1650. }
  1651. return GetCurrentTex();
  1652. }
  1653. public void Draw(int number, State current)
  1654. {
  1655. CurrentFrame = Mathf.RoundToInt((MaxFrame - 1) * current.rates[number]);
  1656. if (!settings.enableOnGUI)
  1657. return;
  1658. alpha.a = current.showSkillSelect || current.showConfigPanel || current.showResultPanel
  1659. ? 0.0f
  1660. : settings.OnGUI_transparency * Mathf.Clamp01(current.rates[number] * 10);
  1661. var texture = current.shotReady
  1662. ? StartCumAnimation(current.isShooting)
  1663. : GetCurrentTex();
  1664. GUI.color = alpha;
  1665. GUI.DrawTexture(ScreenRect.Get(number, current.showParameter), texture, ScaleMode.StretchToFill, true, 0.0f);
  1666. GUI.color = Color.white;
  1667. }
  1668. }
  1669. public class ScreenRect
  1670. {
  1671. private int width, height;
  1672. private float aspect;
  1673. private Rect rect = Rect.zero;
  1674. public void Set(int width, int height)
  1675. {
  1676. this.width = width;
  1677. this.height = height;
  1678. aspect = height != 0 ? (float)this.width / this.height : 1.0f;
  1679. }
  1680. public Rect Get(int n, bool flag)
  1681. {
  1682. if (aspect < 0.001f && aspect > -0.001f)
  1683. aspect = (float)Screen.width / Screen.height;
  1684. var stg = settings;
  1685. var h = Screen.height * 0.2f;
  1686. var w = rect.height * aspect;
  1687. var x = flag ?
  1688. Screen.width - rect.width - Screen.width * 0.17f :
  1689. Screen.width - rect.width - Screen.width * 0.0625f;
  1690. var y = Screen.height - (rect.height + stg.OnGUI_offset) * (n + 1) - Screen.height * 0.111f;
  1691. rect.Set(x + stg.OnGUI_x_offset, y + stg.OnGUI_y_offset,
  1692. w * stg.OnGUI_x_scale, h * stg.OnGUI_y_scale);
  1693. return rect;
  1694. }
  1695. }
  1696. public class Overlay
  1697. {
  1698. public const int OverlayLayer = 13;
  1699. private FlipAnim flipAnim;
  1700. private LineRenderer line;
  1701. private Material material;
  1702. private Shader sprite;
  1703. private Color color = new Color(1, 1, 1, 1);
  1704. public Overlay(FlipAnim flipAnim)
  1705. {
  1706. this.flipAnim = flipAnim;
  1707. }
  1708. private bool SetUpLine()
  1709. {
  1710. if (line == null)
  1711. {
  1712. line = new GameObject($"{PluginName}__Overlay").AddComponent<LineRenderer>();
  1713. material = null;
  1714. sprite = null;
  1715. color = Color.white;
  1716. line.enabled = false;
  1717. }
  1718. else
  1719. {
  1720. line.gameObject.layer = OverlayLayer;
  1721. line.numCapVertices = 0;
  1722. line.shadowCastingMode = ShadowCastingMode.Off;
  1723. line.receiveShadows = false;
  1724. line.alignment = LineAlignment.View;
  1725. line.textureMode = LineTextureMode.Stretch;
  1726. line.useWorldSpace = true;
  1727. sprite = Shader.Find("Sprites/Default");
  1728. if (material == null && sprite)
  1729. {
  1730. material = line.material;
  1731. material.renderQueue = 3030;
  1732. material.shader = sprite;
  1733. material.color = color;
  1734. }
  1735. }
  1736. return line && material && sprite;
  1737. }
  1738. public void Draw(Positions pos, int number, State current)
  1739. {
  1740. if (!settings.enableOverlay)
  1741. {
  1742. Stop();
  1743. return;
  1744. }
  1745. var texture = current.shotReady
  1746. ? flipAnim.StartCumAnimation(current.isShooting)
  1747. : flipAnim.GetCurrentTex();
  1748. if (texture == null || !SetUpLine())
  1749. {
  1750. Stop();
  1751. return;
  1752. }
  1753. color.a = settings.Overlay_Transparency *
  1754. (current.showSkillSelect || current.showConfigPanel || current.showResultPanel
  1755. ? 0
  1756. : Mathf.Clamp01(current.rates[number] * 10));
  1757. material.renderQueue = (int) settings.Overlay_RenderQueue;
  1758. material.mainTexture = texture;
  1759. var aspect = texture.height == 0
  1760. ? (float)texture.width / texture.height
  1761. : 1.0f;
  1762. var dist = Vector3.Distance(pos.Top, pos.Root);
  1763. line.SetPosition(0, pos.Top);
  1764. line.SetPosition(1, pos.Root);
  1765. line.startWidth = dist / aspect * settings.Overlay_LineWidth * 0.5f;
  1766. line.endWidth = dist / aspect * settings.Overlay_LineWidth * 0.5f;
  1767. line.enabled = true;
  1768. if (material)
  1769. material.color = color;
  1770. }
  1771. public void Stop()
  1772. {
  1773. if (line == null)
  1774. return;
  1775. line.enabled = false;
  1776. }
  1777. }
  1778. #region Cams
  1779. private abstract class IOCam : IInitializable
  1780. {
  1781. public const int ManLayer = 9;
  1782. protected static GameObject bgObject;
  1783. protected Camera camera;
  1784. protected RenderTexture renderTexture;
  1785. protected int width, height;
  1786. protected Transform cameraPosition, targetPosition;
  1787. protected Color color;
  1788. public void Initialize()
  1789. {
  1790. renderTexture.Release();
  1791. if (camera)
  1792. camera.enabled = false;
  1793. cameraPosition = null;
  1794. targetPosition = null;
  1795. }
  1796. protected RenderTexture GetRenderTexture()
  1797. {
  1798. renderTexture.Create();
  1799. return renderTexture;
  1800. }
  1801. protected void SetRenderTexture(float width_, float height_)
  1802. {
  1803. if (width_ < 1 || height_ < 1)
  1804. return;
  1805. if (renderTexture.width != (int)width_ || renderTexture.height != (int)height_)
  1806. {
  1807. width = (int)width_;
  1808. height = (int)height_;
  1809. renderTexture = new RenderTexture(width, height, 0);
  1810. }
  1811. }
  1812. protected static Vector3 SmoothCamPos(Vector3 from, Vector3 to, float shakewidth, float smoothspeed)
  1813. {
  1814. var t = Time.time;
  1815. var _x = (Mathf.PerlinNoise(0, t) - 0.5f) * shakewidth;
  1816. var _y = (Mathf.PerlinNoise(t, t) - 0.5f) * shakewidth;
  1817. var _z = (Mathf.PerlinNoise(t, 0) - 0.5f) * shakewidth;
  1818. return new Vector3(
  1819. Mathf.SmoothStep(from.x, to.x + _x, smoothspeed),
  1820. Mathf.SmoothStep(from.y, to.y + _y, smoothspeed),
  1821. Mathf.SmoothStep(from.z, to.z + _z, smoothspeed)
  1822. );
  1823. }
  1824. public abstract void Action();
  1825. public abstract void Draw(State current, Rect rect);
  1826. }
  1827. private class PokoCam : IOCam
  1828. {
  1829. private const string vagina = "_IK_vagina", anal = "_IK_anal", mouth = "Mouth";
  1830. private Vector3 offset;
  1831. public PokoCam()
  1832. {
  1833. color = Color.white;
  1834. renderTexture = new RenderTexture(1, 1, 0);
  1835. }
  1836. ~PokoCam()
  1837. {
  1838. Initialize();
  1839. DestroyObject(camera.gameObject);
  1840. }
  1841. public bool SetupCam(Maid maid, Maid man, MuffType type)
  1842. {
  1843. if (!maid.IsValid() || !man.IsValid())
  1844. return false;
  1845. if (camera == null)
  1846. {
  1847. camera = new GameObject($"{PluginName}__Cam").AddComponent<Camera>();
  1848. camera.nearClipPlane = 0.01f;
  1849. camera.farClipPlane = 100f;
  1850. }
  1851. else
  1852. {
  1853. camera.targetTexture = renderTexture;
  1854. camera.fieldOfView = settings.PokoCam_FOV;
  1855. camera.enabled = false;
  1856. }
  1857. cameraPosition = man.body0.trManChinko;
  1858. switch (type)
  1859. {
  1860. case MuffType.Front:
  1861. targetPosition = maid.body0.GetBone(vagina);
  1862. break;
  1863. case MuffType.Back:
  1864. targetPosition = maid.body0.GetBone(anal);
  1865. break;
  1866. case MuffType.Mouth:
  1867. targetPosition = maid.body0.GetBone(mouth);
  1868. break;
  1869. }
  1870. SetMask(man);
  1871. return camera && cameraPosition && targetPosition;
  1872. }
  1873. private void SetMask(Maid man)
  1874. {
  1875. if (camera == null)
  1876. return;
  1877. var mask = CreateMask();
  1878. camera.cullingMask = ~mask;
  1879. foreach (var m in man.GetComponentsInChildren<SkinnedMeshRenderer>())
  1880. if (m != null)
  1881. m.gameObject.layer = ManLayer;
  1882. }
  1883. private static int CreateMask()
  1884. {
  1885. var mask = 1 << Overlay.OverlayLayer;
  1886. if (settings.PokoCam_HideManBody)
  1887. mask += 1 << ManLayer;
  1888. if (settings.PokoCam_HideBG)
  1889. {
  1890. bgObject = GameMain.Instance.BgMgr.current_bg_object;
  1891. mask += 1 << bgObject.layer;
  1892. }
  1893. return mask;
  1894. }
  1895. public override void Action()
  1896. {
  1897. offset = settings.PokoCam_Offset;
  1898. var newpos = cameraPosition.position + offset;
  1899. var pos = SmoothCamPos(camera.transform.localPosition, newpos,
  1900. settings.PokoCam_ShakeWidth, settings.PokoCam_SmoothSpeed);
  1901. var rot = Quaternion.LookRotation(targetPosition.position - newpos,
  1902. settings.PokoCam_UpsideDown ? -cameraPosition.up : cameraPosition.up);
  1903. camera.transform.SetPositionAndRotation(pos, rot);
  1904. camera.enabled = true;
  1905. }
  1906. public override void Draw(State current, Rect rect)
  1907. {
  1908. var muffType = current.PrimaryMuff;
  1909. if (muffType == MuffType.None)
  1910. return;
  1911. if (current.PokoType != PokoType.TNP && muffType != MuffType.Mouth)
  1912. return;
  1913. color.a = current.showSkillSelect || current.showConfigPanel || current.showResultPanel
  1914. ? 0.0f
  1915. : settings.PokoCam_Transparency * Mathf.Clamp01(current.rates[(int)current.PrimaryMuff] * 10);
  1916. GUI.color = color;
  1917. SetRenderTexture(rect.width, rect.height);
  1918. GUI.DrawTexture(rect, GetRenderTexture(), ScaleMode.ScaleToFit, true);
  1919. GUI.color = Color.white;
  1920. }
  1921. }
  1922. private class FaceCam : IOCam
  1923. {
  1924. private const string FaceNub = "Face_nub";
  1925. private const float FaceOffset = 0.008f;
  1926. public FaceCam()
  1927. {
  1928. color = Color.white;
  1929. renderTexture = new RenderTexture(1, 1, 0);
  1930. }
  1931. ~FaceCam()
  1932. {
  1933. Initialize();
  1934. DestroyObject(camera.gameObject);
  1935. }
  1936. public bool SetupCam(Maid maid)
  1937. {
  1938. if (!maid.IsValid())
  1939. return false;
  1940. if (camera == null)
  1941. {
  1942. camera = new GameObject($"{PluginName}__faceCam").AddComponent<Camera>();
  1943. camera.nearClipPlane = 0.01f;
  1944. camera.farClipPlane = 100f;
  1945. }
  1946. else
  1947. {
  1948. camera.targetTexture = renderTexture;
  1949. camera.fieldOfView = settings.FaceCam_FOV;
  1950. camera.enabled = false;
  1951. }
  1952. targetPosition = maid.IKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Head);
  1953. cameraPosition = GetCameraPos(maid);
  1954. bgObject = GameMain.Instance.BgMgr.current_bg_object;
  1955. var mask = (1 << Overlay.OverlayLayer) + (1 << ManLayer) + (1 << bgObject.layer);
  1956. if (camera != null)
  1957. camera.cullingMask = ~mask;
  1958. return camera && cameraPosition && targetPosition;
  1959. }
  1960. private Transform GetCameraPos(Maid maid)
  1961. {
  1962. var head = maid.body0.goSlot[(int)TBody.SlotID.head].obj_tr;
  1963. for (int j = 0; j < head.childCount; j++)
  1964. {
  1965. var h = head.GetChild(j);
  1966. for (int i = 0; i < h.childCount; i++)
  1967. {
  1968. var f = h.GetChild(i);
  1969. if (f.name.Equals(FaceNub))
  1970. return f;
  1971. }
  1972. }
  1973. return null;
  1974. }
  1975. public override void Draw(State current, Rect rect)
  1976. {
  1977. if (current.rates[2] > 0.01f)
  1978. return;
  1979. color.a = current.showSkillSelect || current.showConfigPanel || current.showResultPanel
  1980. ? 0.0f
  1981. : settings.FaceCam_Transparency;
  1982. GUI.color = color;
  1983. SetRenderTexture(rect.width, rect.height);
  1984. GUI.DrawTexture(rect, GetRenderTexture(), ScaleMode.ScaleToFit, true);
  1985. GUI.color = Color.white;
  1986. }
  1987. public override void Action()
  1988. {
  1989. var dir = targetPosition.position - cameraPosition.position;
  1990. var newpos = cameraPosition.position - dir * settings.FaceCam_Distance;
  1991. var pos = SmoothCamPos(cameraPosition.position, newpos,
  1992. settings.FaceCam_ShakeWidth, settings.FaceCam_SmoothSpeed);
  1993. var rot = Quaternion.LookRotation(dir + cameraPosition.up * FaceOffset, cameraPosition.up);
  1994. camera.transform.SetPositionAndRotation(pos, rot);
  1995. camera.enabled = true;
  1996. }
  1997. }
  1998. #endregion
  1999. public class PokoTrail
  2000. {
  2001. private GameObject obj;
  2002. private TrailRenderer trail;
  2003. private Shader shader;
  2004. private bool SetUpTrail()
  2005. {
  2006. if (shader && trail)
  2007. return true;
  2008. shader = Shader.Find(HiddenShader);
  2009. if (shader == null)
  2010. return false;
  2011. if (trail == null)
  2012. {
  2013. trail = new GameObject($"{PluginName}__trail__").AddComponent<TrailRenderer>();
  2014. obj = trail.gameObject;
  2015. trail.material.shader = shader;
  2016. trail.material.SetInt("_ZTest", (int)CompareFunction.Always);
  2017. trail.startWidth = 0.01f;
  2018. trail.endWidth = 0.0f;
  2019. trail.time = 2;
  2020. trail.minVertexDistance = 0.001f;
  2021. trail.alignment = LineAlignment.View;
  2022. trail.enabled = false;
  2023. }
  2024. return shader && trail;
  2025. }
  2026. public void Draw(Vector3 pos, Color startcolor, Color endcolor)
  2027. {
  2028. if (!SetUpTrail())
  2029. return;
  2030. trail.transform.localPosition = pos;
  2031. trail.startColor = startcolor;
  2032. trail.endColor = endcolor;
  2033. trail.enabled = true;
  2034. }
  2035. ~PokoTrail()
  2036. {
  2037. DestroyObject(trail);
  2038. DestroyObject(obj);
  2039. }
  2040. }
  2041. public class Settings
  2042. {
  2043. private static Settings _instance;
  2044. private static Settings Instance => _instance ?? (_instance = new Settings());
  2045. private static FileInfo fileInfo;
  2046. public bool enablePlugin = false;
  2047. public KeyCode ControllerHotKey = KeyCode.U;
  2048. public float Anim_Speed = 0.5f;
  2049. public bool OnGUI_HidePenis = false;
  2050. //FlipAnim
  2051. public bool enableOnGUI = false;
  2052. public float OnGUI_offset = 5.0f;
  2053. public float OnGUI_x_scale = 1.0f;
  2054. public float OnGUI_y_scale = 1.0f;
  2055. public float OnGUI_x_offset = 0.0f;
  2056. public float OnGUI_y_offset = 0.0f;
  2057. public float OnGUI_transparency = 1.0f;
  2058. //Overlay
  2059. public bool enableOverlay = false;
  2060. public float Overlay_LineWidth = 1.0f;
  2061. public float Overlay_LineScale = 0.0f;
  2062. public float Overlay_Transparency = 0.7f;
  2063. public float Overlay_CameraDistance = 0.25f;
  2064. public float Overlay_DirectionalOffset = 0.0f;
  2065. public float Overlay_RenderQueue = 4000f;
  2066. //Morpher
  2067. public bool enableMorpher = false;
  2068. public float Morpher_Threshold = 0.3f;
  2069. public float Morpher_Min = 0.05f;
  2070. public float Morpher_Max = 0.80f;
  2071. public float Morpher_Waitframe = 5.0f;
  2072. public bool Morpher_EnableFix = true;
  2073. public string Morpher_KeyV = "kupa";
  2074. public string Morpher_KeyA = "analkupa";
  2075. //PokoCam
  2076. public bool enablePokoCam = false;
  2077. //internal Rect PokoCam_Pos = Rect.zero;
  2078. //internal bool PokoCam_CustomPos = false;
  2079. public float PokoCam_FOV = 90.0f;
  2080. public float PokoCam_Transparency = 1.0f;
  2081. public Vector3 PokoCam_Offset = Vector3.zero;
  2082. public bool PokoCam_HideManBody = true;
  2083. public bool PokoCam_HideBG = false;
  2084. public bool PokoCam_UpsideDown = false;
  2085. public float PokoCam_SmoothSpeed = 0.3f;
  2086. public float PokoCam_ShakeWidth = 0.03f;
  2087. //FaceCam
  2088. public bool enableFaceCam = false;
  2089. public float FaceCam_FOV = 20.0f;
  2090. public float FaceCam_Distance = 20.0f;
  2091. public float FaceCam_Transparency = 1.0f;
  2092. public float FaceCam_SmoothSpeed = 0.3f;
  2093. public float FaceCam_ShakeWidth = 0.01f;
  2094. private Settings() { }
  2095. public static void Save()
  2096. {
  2097. if (fileInfo == null)
  2098. return;
  2099. using (var stream = fileInfo.Open(FileMode.Create))
  2100. {
  2101. var serializer = new XmlSerializer(typeof(Settings));
  2102. serializer.Serialize(stream, Instance);
  2103. }
  2104. }
  2105. public static Settings Load() => Load(fileInfo);
  2106. public static Settings Load(FileInfo fileInfo)
  2107. {
  2108. Settings.fileInfo = fileInfo;
  2109. if (!fileInfo.Exists)
  2110. {
  2111. using (fileInfo.Create()) { }
  2112. Save();
  2113. }
  2114. using (var stream = fileInfo.Open(FileMode.Open))
  2115. {
  2116. var serializer = new XmlSerializer(typeof(Settings));
  2117. var reader = XmlReader.Create(stream, new XmlReaderSettings());
  2118. return _instance = (Settings)serializer.Deserialize(reader);
  2119. }
  2120. }
  2121. public static Settings GetDef()
  2122. {
  2123. var _ = new Settings();
  2124. return ReferenceEquals(_, _instance) ? null : _;
  2125. }
  2126. public void OpenFile()
  2127. {
  2128. if (!fileInfo.Exists)
  2129. return;
  2130. var ps = new ProcessStartInfo
  2131. {
  2132. FileName = "notepad",
  2133. Arguments = fileInfo.FullName
  2134. };
  2135. using (var process = Process.Start(ps)) { };
  2136. }
  2137. }
  2138. private class Controller
  2139. {
  2140. private bool _show = false;
  2141. public bool showController
  2142. {
  2143. get => _show;
  2144. set
  2145. {
  2146. var mouse = Event.current.mousePosition;
  2147. winRect.Set(
  2148. Mathf.Clamp(mouse.x - 10.0f, 0.0f, Screen.width - Screen.width * 0.25f),
  2149. Mathf.Clamp(mouse.y - 10.0f, 0.0f, Screen.height - 400),
  2150. Screen.width * 0.25f,
  2151. Screen.height * 0.6f);
  2152. _show = value;
  2153. GC.Collect();
  2154. }
  2155. }
  2156. private readonly InOutAnimation plugin;
  2157. private static Rect winRect;
  2158. private Vector2 winScrollRect;
  2159. private static readonly Color bgColor = Color.white, onColor = Color.green, offColor = Color.black;
  2160. private const string MuffNames = "前後口";
  2161. private const string TargetMaid = "対象メイド";
  2162. private const string PokoNames = "棒振張指舌";
  2163. private FlipAnimData[] fAData;
  2164. private ToggleButton pluginEnabler;
  2165. private Dictionary<string, Container> containers;
  2166. private static GUILayoutOption[] noOptions = new GUILayoutOption[0];
  2167. private static GUILayoutOption noExpandWidth = ExpandWidth(false);
  2168. private static GUILayoutOption width010, width015, width020, width025;
  2169. public Controller(InOutAnimation plugin)
  2170. {
  2171. this.plugin = plugin;
  2172. var s = settings;
  2173. var def = Settings.GetDef();
  2174. fAData = new[]
  2175. {
  2176. new FlipAnimData($"{MuffNames[0]}", plugin.flipAnims[0]),
  2177. new FlipAnimData($"{MuffNames[1]}", plugin.flipAnims[1]),
  2178. new FlipAnimData($"{MuffNames[2]}", plugin.flipAnims[2])
  2179. };
  2180. pluginEnabler = new ToggleButton("プラグイン有効", s.enablePlugin, b => settings.enablePlugin = b);
  2181. containers = new Dictionary<string, Container>
  2182. {
  2183. {"ongui", new Container("OnGUI表示")},
  2184. {"overlay", new Container("メイドに重ねて表示")},
  2185. {"morpher", new Container("シェイプキー連動")},
  2186. {"pokocam", new Container("股間視点")},
  2187. {"facecam", new Container("顔カメラ")}
  2188. };
  2189. containers["ongui"].Add(new ToggleButton("有効", s.enableOnGUI, b => settings.enableOnGUI = b));
  2190. containers["ongui"].Add(new LabelSlider("間隔", s.OnGUI_offset, -100.0f, 100.0f, def.OnGUI_offset, f => settings.OnGUI_offset = f));
  2191. containers["ongui"].Add(new LabelSlider("横スケール", s.OnGUI_x_scale, 0.0f, 2.0f, def.OnGUI_x_scale, f => settings.OnGUI_x_scale = f));
  2192. containers["ongui"].Add(new LabelSlider("縦スケール", s.OnGUI_y_scale, 0.0f, 2.0f, def.OnGUI_y_scale, f => settings.OnGUI_y_scale = f));
  2193. containers["ongui"].Add(new LabelSlider("横オフセット", s.OnGUI_x_offset, -600.0f, 300.0f, def.OnGUI_x_offset, f => settings.OnGUI_x_offset = f));
  2194. containers["ongui"].Add(new LabelSlider("縦オフセット", s.OnGUI_y_offset, -500.0f, 500.0f, def.OnGUI_y_offset, f => settings.OnGUI_y_offset = f));
  2195. containers["ongui"].Add(new LabelSlider("透明度", s.OnGUI_transparency, 0.0f, 1.0f, def.OnGUI_transparency, f => settings.OnGUI_transparency = f));
  2196. containers["ongui"].Add(new ToggleButton("Hide man penis", s.OnGUI_HidePenis, b => settings.OnGUI_HidePenis = b));
  2197. containers["overlay"].Add(new ToggleButton("有効", s.enableOverlay, b => settings.enableOverlay = b));
  2198. containers["overlay"].Add(new LabelSlider("太さ", s.Overlay_LineWidth, 0.0f, 2.0f, def.Overlay_LineWidth, f => settings.Overlay_LineWidth = f));
  2199. containers["overlay"].Add(new LabelSlider("拡大", s.Overlay_LineScale, -0.5f, 0.5f, def.Overlay_LineScale, f => settings.Overlay_LineScale = f));
  2200. containers["overlay"].Add(new LabelSlider("透明度", s.Overlay_Transparency, 0.0f, 1.0f, def.Overlay_Transparency, f => settings.Overlay_Transparency = f));
  2201. containers["overlay"].Add(new LabelSlider("カメラ距離", s.Overlay_CameraDistance, 0.0f, 1.0f, def.Overlay_CameraDistance, f => settings.Overlay_CameraDistance = f));
  2202. containers["overlay"].Add(new LabelSlider("Dir. Offset.", s.Overlay_DirectionalOffset, -0.1f, 0.1f, def.Overlay_DirectionalOffset, f => settings.Overlay_DirectionalOffset = f));
  2203. containers["overlay"].Add(new LabelSlider("Overlay renderqueue", s.Overlay_RenderQueue, 1000, 5000, def.Overlay_RenderQueue, f => settings.Overlay_RenderQueue = f, true));
  2204. containers["morpher"].Add(new ToggleButton("有効", s.enableMorpher, b => settings.enableMorpher = b));
  2205. containers["morpher"].Add(new ShapeKeyChange("前穴用キー", s.Morpher_KeyV, n => settings.Morpher_KeyV = n));
  2206. containers["morpher"].Add(new ShapeKeyChange("後穴用キー", s.Morpher_KeyA, n => settings.Morpher_KeyA = n));
  2207. containers["morpher"].Add(new LabelSlider("閾値", s.Morpher_Threshold, 0.0f, 1.0f, def.Morpher_Threshold, f => settings.Morpher_Threshold = f));
  2208. containers["morpher"].Add(new LabelSlider("最小値", s.Morpher_Min, 0.0f, 1.0f, def.Morpher_Min, f => settings.Morpher_Min = f));
  2209. containers["morpher"].Add(new LabelSlider("最大値", s.Morpher_Max, 0.0f, 1.0f, def.Morpher_Max, f => settings.Morpher_Max = f));
  2210. var wf = new LabelSlider("更新フレーム", s.Morpher_Waitframe, 1, 60, def.Morpher_Waitframe, f => settings.Morpher_Waitframe = f, true);
  2211. containers["morpher"].Add(new EnableToggle("FixBlendValues", s.Morpher_EnableFix, wf, b => settings.Morpher_EnableFix = b));
  2212. containers["pokocam"].Add(new ToggleButton("有効", s.enablePokoCam, b => settings.enablePokoCam = b));
  2213. var st1 = new SimpleToggle("男を隠す", s.PokoCam_HideManBody, b => settings.PokoCam_HideManBody = b);
  2214. // var st2 = new SimpleToggle("背景を隠す", s.PokoCam_HideBG, b => settings.PokoCam_HideBG = b);
  2215. var st3 = new SimpleToggle("上下逆", s.PokoCam_UpsideDown, b => settings.PokoCam_UpsideDown = b);
  2216. containers["pokocam"].Add(new HorizontalGroup(st1, st3));
  2217. containers["pokocam"].Add(new LabelSlider("視野", s.PokoCam_FOV, 15, 180, def.PokoCam_FOV, f => settings.PokoCam_FOV = f, true));
  2218. containers["pokocam"].Add(new LabelSlider("透明度", s.PokoCam_Transparency, 0.0f, 1.0f, def.PokoCam_Transparency, f => settings.PokoCam_Transparency = f));
  2219. containers["pokocam"].Add(new Vec3Slider("オフセット", s.PokoCam_Offset, def.PokoCam_Offset, -0.2f, 0.2f, v => settings.PokoCam_Offset = v));
  2220. containers["facecam"].Add(new ToggleButton("有効", s.enableFaceCam, b => settings.enableFaceCam = b));
  2221. containers["facecam"].Add(new LabelSlider("距離", s.FaceCam_Distance, 5.0f, 40.0f, def.FaceCam_Distance, f => settings.FaceCam_Distance = f));
  2222. containers["facecam"].Add(new LabelSlider("視野", s.FaceCam_FOV, 15, 50, def.FaceCam_FOV, f => settings.FaceCam_FOV = f, true));
  2223. containers["facecam"].Add(new LabelSlider("透明度", s.FaceCam_Transparency, 0.0f, 1.0f, def.FaceCam_Transparency, f => settings.FaceCam_Transparency = f));
  2224. }
  2225. public void Draw()
  2226. {
  2227. winRect = Window(plugin.windowId, winRect, WindowFunc, "", noOptions);
  2228. }
  2229. private void WindowFunc(int id)
  2230. {
  2231. var stg = settings;
  2232. winScrollRect = BeginScrollView(winScrollRect, false, false, noOptions);
  2233. pluginEnabler.Draw();
  2234. //if (Button("設定ファイルを開く", ExpandWidth(false))) settings.OpenFile();
  2235. if (stg.enablePlugin && plugin.mediator.TargetMaid != null)
  2236. {
  2237. BeginHorizontal(noOptions);
  2238. {
  2239. Label(TargetMaid, noExpandWidth);
  2240. Box(plugin.current.isPlay ? plugin.mediator.TargetMaid.status.fullNameJpStyle : "", noOptions);
  2241. plugin.mediator.SwapTargetNPC = plugin.current.PlayMode == PlayMode.Swap
  2242. && Toggle(plugin.mediator.SwapTargetNPC, "NPC", noExpandWidth);
  2243. }
  2244. EndHorizontal();
  2245. foreach (var fA in fAData)
  2246. fA.Draw();
  2247. for (var i = 0; i < plugin.mediator.pokos.Length; i++)
  2248. {
  2249. var p = plugin.mediator.pokos[i];
  2250. if (p == null || !p.Validated)
  2251. continue;
  2252. BeginHorizontal(noOptions);
  2253. {
  2254. Box($"{i} {GetPokoTypeChar(p)} : {MuffNames[(int)p.TargetMuff]}", noOptions);
  2255. }
  2256. EndHorizontal();
  2257. }
  2258. foreach (var container in containers.Values)
  2259. container.Draw();
  2260. }
  2261. EndScrollView();
  2262. GUI.DragWindow();
  2263. }
  2264. private char GetPokoTypeChar(Poko type)
  2265. {
  2266. switch (type)
  2267. {
  2268. case TNP _: return PokoNames[0];
  2269. case Vibe _: return PokoNames[1];
  2270. case Dildo _: return PokoNames[2];
  2271. case Finger _: return PokoNames[3];
  2272. case Tongue _: return PokoNames[4];
  2273. }
  2274. return '_';
  2275. }
  2276. private class Container
  2277. {
  2278. private readonly string label;
  2279. private bool visible;
  2280. private List<IDrawable> contents;
  2281. private const string Down = "▼";
  2282. public Container(string label)
  2283. {
  2284. this.label = label;
  2285. contents = new List<IDrawable>();
  2286. }
  2287. public void Add(IDrawable controllerParts) => contents.Add(controllerParts);
  2288. public void Draw()
  2289. {
  2290. BeginHorizontal(noOptions);
  2291. {
  2292. Box(label, noOptions);
  2293. if (Button(Down, noExpandWidth))
  2294. visible = !visible;
  2295. }
  2296. EndHorizontal();
  2297. if (!visible)
  2298. return;
  2299. foreach (var drawable in contents)
  2300. drawable.Draw();
  2301. }
  2302. }
  2303. private class HorizontalGroup : IDrawable
  2304. {
  2305. private List<IDrawable> contents;
  2306. public HorizontalGroup(params IDrawable[] drawable)
  2307. {
  2308. contents = drawable.ToList();
  2309. }
  2310. public void Add(IDrawable drawable) => contents.Add(drawable);
  2311. public void Draw()
  2312. {
  2313. BeginHorizontal(noOptions);
  2314. foreach (var drawable in contents)
  2315. {
  2316. drawable.Draw();
  2317. }
  2318. EndHorizontal();
  2319. }
  2320. }
  2321. private class FlipAnimData : IDrawable
  2322. {
  2323. private string label;
  2324. private FlipAnim flipAnim;
  2325. private static Color color;
  2326. private string message;
  2327. private const string Reload = "再読込",
  2328. mes1 = "準備完了", mes2 = "ex画像がありません", mes3 = "画像がありません";
  2329. public FlipAnimData(string label, FlipAnim flipAnim)
  2330. {
  2331. this.label = label;
  2332. this.flipAnim = flipAnim;
  2333. }
  2334. public void Draw()
  2335. {
  2336. CheckLoaded();
  2337. BeginHorizontal(noOptions);
  2338. {
  2339. width010 = Width(winRect.width * 0.10f);
  2340. width015 = Width(winRect.width * 0.15f);
  2341. width020 = Width(winRect.width * 0.20f);
  2342. Label(label, width010);
  2343. Box($"{flipAnim.CurrentFrame:D2}/{flipAnim.MaxFrame:D2}", width020);
  2344. GUI.contentColor = color;
  2345. Box($"{message}", noOptions);
  2346. GUI.contentColor = bgColor;
  2347. if (Button(Reload, width015))
  2348. flipAnim.Load();
  2349. }
  2350. EndHorizontal();
  2351. }
  2352. private void CheckLoaded()
  2353. {
  2354. if (flipAnim.TextureLoaded)
  2355. {
  2356. if (flipAnim.TextureLoadedEx)
  2357. {
  2358. color = Color.white;
  2359. message = mes1;
  2360. return;
  2361. }
  2362. color = Color.yellow;
  2363. message = mes2;
  2364. return;
  2365. }
  2366. color = Color.magenta;
  2367. message = mes3;
  2368. }
  2369. }
  2370. private class SimpleToggle : IDrawable
  2371. {
  2372. private string label;
  2373. private bool recent;
  2374. private bool value;
  2375. private Action<bool> onChanged;
  2376. public SimpleToggle(string label, bool value, Action<bool> onChanged)
  2377. {
  2378. this.label = label;
  2379. this.value = value;
  2380. recent = this.value;
  2381. this.onChanged = onChanged;
  2382. }
  2383. public void Draw()
  2384. {
  2385. value = Toggle(value, label, noOptions);
  2386. if (recent == value)
  2387. return;
  2388. onChanged(value);
  2389. recent = value;
  2390. }
  2391. }
  2392. private class Vec3Slider : IDrawable
  2393. {
  2394. private string label;
  2395. private Vector3 value, recent;
  2396. private readonly Vector3 def;
  2397. private readonly float min, max;
  2398. private Action<Vector3> onChanged;
  2399. public Vec3Slider(string label, Vector3 value, Vector3 def, float min, float max, Action<Vector3> onChanged)
  2400. {
  2401. this.label = label;
  2402. this.value = value;
  2403. recent = this.value;
  2404. this.def = def;
  2405. this.min = min;
  2406. this.max = max;
  2407. this.onChanged = onChanged;
  2408. }
  2409. public void Draw()
  2410. {
  2411. BeginHorizontal(noOptions);
  2412. {
  2413. Label(label, noOptions);
  2414. if (Button("def", noExpandWidth))
  2415. value = def;
  2416. }
  2417. EndHorizontal();
  2418. BeginHorizontal(noOptions);
  2419. {
  2420. Label("X", noExpandWidth);
  2421. value.x = HorizontalSlider(value.x, min, max, noOptions);
  2422. Label("Y", noExpandWidth);
  2423. value.y = HorizontalSlider(value.y, min, max, noOptions);
  2424. Label("Z", noExpandWidth);
  2425. value.z = HorizontalSlider(value.z, min, max, noOptions);
  2426. }
  2427. EndHorizontal();
  2428. if (recent.Equals(value))
  2429. return;
  2430. onChanged(value);
  2431. recent = value;
  2432. }
  2433. }
  2434. private class EnableToggle : IDrawable
  2435. {
  2436. private readonly string label;
  2437. private bool enable, recent;
  2438. private IDrawable parts;
  2439. private Action<bool> onChanged;
  2440. public EnableToggle(string label, bool enable, IDrawable parts, Action<bool> onChanged)
  2441. {
  2442. this.label = label;
  2443. this.enable = enable;
  2444. this.parts = parts;
  2445. this.onChanged = onChanged;
  2446. }
  2447. public void Draw()
  2448. {
  2449. enable = Toggle(enable, label, noOptions);
  2450. GUI.enabled = enable;
  2451. parts.Draw();
  2452. GUI.enabled = true;
  2453. if (recent == enable)
  2454. return;
  2455. onChanged(enable);
  2456. recent = enable;
  2457. }
  2458. }
  2459. private class ShapeKeyChange : IDrawable
  2460. {
  2461. private readonly string label;
  2462. private string key, recent;
  2463. private bool Editable;
  2464. private Action<string> onChanged;
  2465. private const string Change = "変更";
  2466. public ShapeKeyChange(string label, string key, Action<string> onChanged)
  2467. {
  2468. this.label = label;
  2469. this.key = key;
  2470. recent = key;
  2471. this.onChanged = onChanged;
  2472. }
  2473. public void Draw()
  2474. {
  2475. width025 = Width(winRect.width * 0.25f);
  2476. BeginHorizontal(noOptions);
  2477. Label(label, width025);
  2478. if (Editable)
  2479. try
  2480. {
  2481. key = TextArea($"{key}", noOptions).Trim();
  2482. }
  2483. catch (FormatException e)
  2484. {
  2485. Console.WriteLine(e);
  2486. key = "";
  2487. }
  2488. else
  2489. Box($"{key}", noOptions);
  2490. GUI.backgroundColor = Editable ? onColor : offColor;
  2491. if (Button(Change, noExpandWidth))
  2492. Editable = !Editable;
  2493. GUI.backgroundColor = bgColor;
  2494. EndHorizontal();
  2495. if (recent.Equals(key))
  2496. return;
  2497. onChanged(key);
  2498. recent = key;
  2499. }
  2500. }
  2501. private class ToggleButton : IDrawable
  2502. {
  2503. private readonly string label;
  2504. private bool value, recent;
  2505. private Action<bool> onChanged;
  2506. public ToggleButton(string label, bool value, Action<bool> onChanged)
  2507. {
  2508. this.label = label;
  2509. this.value = value;
  2510. recent = value;
  2511. this.onChanged = onChanged;
  2512. }
  2513. public void Draw()
  2514. {
  2515. GUI.backgroundColor = value ? onColor : offColor;
  2516. if (Button(label, noOptions))
  2517. value = !value;
  2518. GUI.backgroundColor = bgColor;
  2519. if (recent == value)
  2520. return;
  2521. onChanged(value);
  2522. recent = value;
  2523. }
  2524. }
  2525. private class LabelSlider : IDrawable
  2526. {
  2527. private readonly string label;
  2528. private float value, recent;
  2529. private string str;
  2530. private readonly float min, max, def;
  2531. private readonly bool ceil;
  2532. private Action<float> onChanged;
  2533. private const string _def = "def";
  2534. public LabelSlider(string label, float value, float min, float max, float def, Action<float> onChanged, bool ceil = false)
  2535. {
  2536. this.label = label;
  2537. this.value = value;
  2538. recent = this.value;
  2539. this.min = min;
  2540. this.max = max;
  2541. this.def = def;
  2542. this.ceil = ceil;
  2543. this.onChanged = onChanged;
  2544. }
  2545. public void Draw()
  2546. {
  2547. width015 = Width(winRect.width * 0.15f);
  2548. width025 = Width(winRect.width * 0.25f);
  2549. BeginHorizontal(noOptions);
  2550. {
  2551. if (ceil)
  2552. value = Mathf.Ceil(value);
  2553. str = ceil ? $"{value}" : $"{value:F2}";
  2554. Label(label, width025);
  2555. Box(str, width015);
  2556. value = HorizontalSlider(value, min, max, noOptions);
  2557. if (Button(_def, noExpandWidth))
  2558. value = def;
  2559. }
  2560. EndHorizontal();
  2561. if (recent.Equals(value))
  2562. return;
  2563. onChanged(value);
  2564. recent = value;
  2565. }
  2566. }
  2567. private interface IDrawable
  2568. {
  2569. void Draw();
  2570. }
  2571. }
  2572. private class MessageBox
  2573. {
  2574. private readonly Rect winRect = new Rect(30, Screen.height * 0.5f, 400, 300);
  2575. private GUIContent message;
  2576. public void Draw(GUIContent content)
  2577. {
  2578. message = content;
  2579. BeginArea(winRect);
  2580. {
  2581. Box(message);
  2582. }
  2583. EndArea();
  2584. }
  2585. }
  2586. #endregion
  2587. private interface IInitializable { void Initialize(); }
  2588. }
  2589. public static class Util
  2590. {
  2591. public static bool IsValid(this Maid maid)
  2592. {
  2593. return maid != null && maid.isActiveAndEnabled &&
  2594. !maid.IsAllProcPropBusy && maid.Visible &&
  2595. !string.IsNullOrEmpty(maid.body0.LastAnimeFN);
  2596. }
  2597. public static IEnumerable<Maid> GetMaidCol(this CharacterMgr mgr, Func<Maid, bool> pred)
  2598. {
  2599. return Enumerable.Range(0, mgr.GetMaidCount()).Select(mgr.GetMaid).Where(pred);
  2600. }
  2601. }
  2602. #region enums
  2603. internal enum MuffNum { Unknown, Double, Triple }
  2604. internal enum MuffType { Front, Back, Mouth, None }
  2605. internal enum PlayMode { Normal, Multiple, Swap, Harem, Self }
  2606. internal enum sPosition { None, Normal, Dog, Side }
  2607. internal enum PlayState { None, Insert, Eject, Wait, Play, Shot, ShotFin }
  2608. internal enum PokoType { TNP, Vibe, Dildo, Finger, Tongue }
  2609. #endregion
  2610. }