Skip to content

Commit

Permalink
Merge pull request #1 from YutoMaeda1209/dev
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
YutoMaeda1209 authored Sep 15, 2024
2 parents 41abff5 + 10e0f8b commit 732295e
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 3 deletions.
52 changes: 52 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,55 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

----------------------------------------------------------------------------

PrimitierNOVRDBG

MIT License

Copyright (c) 2023 Seva167

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

----------------------------------------------------------------------------

Best-README-Template

MIT License

Copyright (c) 2019-2024 Othneil Drew

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 27 additions & 0 deletions Patches/HeightCalibrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using HarmonyLib;
using Il2Cpp;
using MelonLoader;
using UnityEngine;

namespace YuchiGames.PrimitierDesktop.Patches
{
[HarmonyPatch(typeof(HeightCalibrator), nameof(HeightCalibrator.Initialize))]
public class HeightCalibrator_Initialize
{
public static void Postfix()
{
HeightCalibrator heightCalibrator = GameObject.FindObjectOfType<HeightCalibrator>();
heightCalibrator.Calibrate();
}
}

[HarmonyPatch(typeof(HeightCalibrator), nameof(HeightCalibrator.Calibrate))]
public class HeightCalibrator_Calibrate
{
public static void Postfix()
{
HeightCalibrator heightCalibrator = GameObject.FindObjectOfType<HeightCalibrator>();
heightCalibrator.ShowTitleMenu();
}
}
}
21 changes: 21 additions & 0 deletions PrimitierDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@
<Reference Include="MelonLoader">
<HintPath>$(PRIMITIER_PATH)\MelonLoader\net6\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="Unity.InputSystem">
<HintPath>$(PRIMITIER_PATH)\MelonLoader\Il2CppAssemblies\Unity.InputSystem.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(PRIMITIER_PATH)\MelonLoader\Il2CppAssemblies\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(PRIMITIER_PATH)\MelonLoader\Il2CppAssemblies\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>$(PRIMITIER_PATH)\MelonLoader\Il2CppAssemblies\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>$(PRIMITIER_PATH)\MelonLoader\Il2CppAssemblies\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(PRIMITIER_PATH)\MelonLoader\Il2CppAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>$(PRIMITIER_PATH)\MelonLoader\Il2CppAssemblies\UnityEngine.UIModule.dll</HintPath>
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
Expand Down
154 changes: 153 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,161 @@
using MelonLoader;
using Il2Cpp;
using MelonLoader;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.XR;
using UnityEngine.UI;

namespace YuchiGames.PrimitierDesktop
{
public class Program : MelonMod
{
bool _initialized = false;
GameObject _xrOrigin = new GameObject();
GameObject _leftHandCtrl = new GameObject();
GameObject _rightHandCtrl = new GameObject();
GameObject _mainCamera = new GameObject();

public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
GameObject mainCanvas = GameObject.Find("/Player/XR Origin/Camera Offset/LeftHand Controller/RealLeftHand/MenuWindowL/Windows/MainCanvas");
mainCanvas.transform.Find("CameraTab").gameObject.SetActive(false);
mainCanvas.transform.Find("CameraTabButton").gameObject.SetActive(false);

GameObject.Find("/HandyCamera").SetActive(false);
foreach (Canvas canvas in GameObject.FindObjectsOfType<Canvas>(true))
{
canvas.gameObject.AddComponent<GraphicRaycaster>();
}

_xrOrigin = GameObject.Find("/Player/XR Origin");
InputActionMap inputActionMap = _xrOrigin.GetComponent<PlayerInput>()
.actions.actionMaps[0];
// Move
inputActionMap.actions[0].AddCompositeBinding("2DVector")
.With("Up", "<Keyboard>/w")
.With("Down", "<Keyboard>/s")
.With("Left", "<Keyboard>/a")
.With("Right", "<Keyboard>/d");
// Jump
inputActionMap.actions[4].AddBinding("<Keyboard>/space");
// Grab
inputActionMap.actions[7].AddBinding("<Keyboard>/h");
inputActionMap.actions[8].AddBinding("<Keyboard>/j");
// Bond
inputActionMap.actions[9].AddBinding("<Keyboard>/t");
inputActionMap.actions[10].AddBinding("<Keyboard>/y");
// Menu
inputActionMap.actions[11].AddBinding("<Keyboard>/n");
inputActionMap.actions[12].AddBinding("<Keyboard>/m");
// Separate
inputActionMap.actions[13].AddBinding("<Keyboard>/u");
inputActionMap.actions[14].AddBinding("<Keyboard>/i");

_mainCamera = GameObject.Find("/Player/XR Origin/Camera Offset/Main Camera");
_mainCamera.GetComponent<Camera>().fieldOfView = 90f;
_mainCamera.GetComponent<TrackedPoseDriver>().enabled = false;
_mainCamera.transform.localPosition = new Vector3(0f, 1.8f, 0f);

_leftHandCtrl = GameObject.Find("/Player/XR Origin/Camera Offset/LeftHand Controller");
Grabber leftGrabber = GameObject.Find("/Player/LeftHand").GetComponent<Grabber>();
Hand leftHand = leftGrabber.GetComponent<Hand>();
leftHand.maximumForce = float.PositiveInfinity;
leftHand.maximumTorque = float.PositiveInfinity;
leftHand.positionSpring = 1000000f;
leftHand.rotationSpring = 1000000f;

_rightHandCtrl = GameObject.Find("/Player/XR Origin/Camera Offset/RightHand Controller");
Grabber rightGrabber = GameObject.Find("/Player/RightHand").GetComponent<Grabber>();
Hand rightHand = rightGrabber.GetComponent<Hand>();
rightHand.maximumForce = float.PositiveInfinity;
rightHand.maximumTorque = float.PositiveInfinity;
rightHand.positionSpring = 1000000f;
rightHand.rotationSpring = 1000000f;

_initialized = true;
}

Vector3 _leftHandMove = new Vector3(-0.1f, -0.2f, 0.15f);
Vector3 _leftHandRot = new Vector3(270f, 0f, 0f);
Vector3 _rightHandMove = new Vector3(0.1f, -0.2f, 0.15f);
Vector3 _rightHandRot = new Vector3(270f, 0f, 0f);
bool _hideMouse = false;
bool _isEscape = false;

public override void OnUpdate()
{
if (!_initialized)
return;

_leftHandCtrl.transform.position = _mainCamera.transform.TransformPoint(_leftHandMove);
_leftHandCtrl.transform.rotation = _mainCamera.transform.rotation * Quaternion.Euler(_leftHandRot);

if (Input.GetMouseButton(0))
{
if (Input.GetMouseButton(2))
{
_leftHandRot += new Vector3(Input.GetAxis("Mouse Y"), -Input.GetAxis("Mouse X"));
return;
}

_leftHandMove += new Vector3(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), Input.mouseScrollDelta.y) * 0.05f;
}
if (Input.GetKeyDown(KeyCode.Q))
{
_leftHandMove = new Vector3(-0.1f, -0.2f, 0.15f);
_leftHandRot = new Vector3(270f, 0f, 0f);
}

_rightHandCtrl.transform.position = _mainCamera.transform.TransformPoint(_rightHandMove);
_rightHandCtrl.transform.rotation = _mainCamera.transform.rotation * Quaternion.Euler(_rightHandRot);

if (Input.GetMouseButton(1))
{
if (Input.GetMouseButton(2))
{
_rightHandRot += new Vector3(Input.GetAxis("Mouse Y"), -Input.GetAxis("Mouse X"));
return;
}

_rightHandMove += new Vector3(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), Input.mouseScrollDelta.y) * 0.05f;
}
if (Input.GetKeyDown(KeyCode.E))
{
_rightHandMove = new Vector3(0.1f, -0.2f, 0.15f);
_rightHandRot = new Vector3(270f, 0f, 0f);
}

if (!(Input.GetMouseButton(0) || Input.GetMouseButton(1)) && _hideMouse)
{
_xrOrigin.transform.rotation = Quaternion.Euler(0f, Input.GetAxis("Mouse X") + _xrOrigin.transform.rotation.eulerAngles.y, 0f);
}
if (!(Input.GetMouseButton(0) || Input.GetMouseButton(1)) && _hideMouse)
{
_mainCamera.transform.localRotation = Quaternion.Euler(-Input.GetAxis("Mouse Y") + _mainCamera.transform.localRotation.eulerAngles.x, 0f, 0f);
}

if (Input.GetKeyDown(KeyCode.Escape))
{
_isEscape = !_isEscape;
SwitchHideMouse(!_hideMouse);
}
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
{
if (_isEscape)
SwitchHideMouse(true);
}
if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1))
{
if (!_isEscape)
SwitchHideMouse(false);
}
}

public void SwitchHideMouse(bool isHideButton)
{
_hideMouse = isHideButton;
Cursor.lockState = _hideMouse ? CursorLockMode.Locked : CursorLockMode.None;
Cursor.visible = !_hideMouse;
}
}
}
111 changes: 109 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,109 @@
# PrimitierDesktop

<p align=center>
<a href="https://github.com/YutoMaeda1209/PrimitierDesktop/releases/latest"><img src="https://img.shields.io/badge/Download-latest-blue?style=for-the-badge"/></a>
<a href="https://github.com/YutoMaeda1209/PrimitierDesktop/releases"><img src="https://img.shields.io/github/v/release/YutoMaeda1209/PrimitierDesktop?style=for-the-badge"/></a>
<a href="https://store.steampowered.com/app/1745170/Primitier/"><img src="https://img.shields.io/badge/Primitier-v1.9.0-limegreen?style=for-the-badge"/></a>
<a href="https://discord.com/channels/968161559387979876/1262816599174549524"><img src="https://img.shields.io/badge/-Discord-gray?style=for-the-badge&logo=Discord&logoColor=white"/></a>
</p>

<div align="center">
<h3 align="center">PrimitierDesktop</h3>
<p align="center">
Mod to allow Primitier to be played without VR equipment.
<br />
<br />
<a href="https://github.com/YutoMaeda1209/PrimitierDesktop/issues/new?labels=bug&template=bug-report---.md">Report Bug</a>
·
<a href="https://github.com/YutoMaeda1209/PrimitierDesktop/issues/new?labels=enhancement&template=feature-request---.md">Request Feature</a>
</p>
</div>

<details>
<summary>Table of Contents</summary>
<ol>
<li>
<a href="#about-the-project">About The Project</a>
</li>
<li>
<a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li>
<a href="#usage">Usage</a>
<ul>
<li><a href="#controls">Controls</a></li>
</ul>
</li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#license">License</a></li>
<li><a href="#acknowledgments">Acknowledgments</a></li>
</ol>
</details>

## About The Project

This is a mod that allows Primitier to be controlled by keyboard and mouse. To avoid interfering with other mods, we have made it so that it does not directly enable or disable any objects in the game as much as possible. Therefore, it can be used as a debugging tool for mods.

## Getting Started

How to install the mod to Primitier.

### Prerequisites

Install the tools needed to install the mod.

- [MelonLoader](https://melonwiki.xyz/)

### Installation

1. download the mod from the release page.
2. put `PrimitierDesktop.dll` in Primitier/Mods folder.
3. Play Primitier!

## Usage

### Controls

| Action | Left hand | Right hand |
|------------------|-----------|------------|
| Toggle hand menu | N | M |
| Toggle grab | H | J |
| Bind cubes | T | Y |
| Separate cubes | U | I |
| Reset position | Q | E |

| Action | Key |
|---------------|-------------|
| Toggle cursor | Escape |
| Rotate hand | Mouse Wheel |

## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

### Top contributors:

<a href="https://github.com/YutoMaeda1209/PrimitierOnlineMod/graphs/contributors">
<img src="https://contrib.rocks/image?repo=YutoMaeda1209/PrimitierOnlineMod" alt="contrib.rocks image" />
</a>

## License

Distributed under the MIT License. See `LICENSE.txt` for more information.

## Acknowledgments

This is the project I referred to in creating this project.

* [PrimitierNOVRDBG](https://github.com/Seva167/PrimitierNOVRDBG)

0 comments on commit 732295e

Please sign in to comment.