InOutAnimation.cs 112 KB

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