Compare commits

...

172 commits

Author SHA1 Message Date
966fdd4c3a Fix even more issues uncovered by tests
- Fixed the time mode toggle not working during testing (changed the runner)
- Made the testing thing wait until the time toggle finishes
- Fixed the Game.Enter/Exit event being triggered on time mode change
- Added a way to spawn and despawn the player's machine (which doesn't work yet)
- Fixed the Player.Id property always being 0
- Attempted to fix the fake action inputs not working in simulation
2022-01-07 02:14:58 +01:00
5602ef9268 All kinds of fixes of issues during automatic tests
- Fixed toggling time running mode
- Fixed closing popups
- Added support for pressing the buttons on a popup
- Added error handling to Main.Init()
- Automatically closing the beta message in the test plugin
- Fixed Game.EnterGame() causing a crash in the game
2021-12-28 15:09:01 +01:00
93a0b2287a Added player join/leave events and fix errors
- Fixed anticheat status error spam
- Fixed IMGUI not actually running on OnGUI because that runner was changed in Svelto
- Added player join and leave events
- Made Game.Enter only trigger when both the game has finished loading *and* the local player has joined
2021-12-27 02:28:09 +01:00
4ac8d53a2d Organize anti-anticheat, add block IDs, fix crash when adding event handlers multiple times 2021-12-26 23:37:02 +01:00
f817becc6e Resolve all compile-time and patching errors, remove anticheat in singleplayer 2021-12-16 21:13:45 +01:00
2a1782cd82 Start updating to 2021.12.14.17.00
A bunch of errors still
2021-12-15 03:46:38 +01:00
fef66c349d Merge branch 'master' into preview
# Conflicts:
#	Automation/gen_csproj.py
#	GamecraftModdingAPI/App/AppEngine.cs
#	GamecraftModdingAPI/App/GameGameEngine.cs
#	GamecraftModdingAPI/App/GameMenuEngine.cs
#	GamecraftModdingAPI/Block.cs
#	GamecraftModdingAPI/Blocks/BlockEngine.cs
#	GamecraftModdingAPI/Blocks/BlockEngineInit.cs
#	GamecraftModdingAPI/Blocks/BlockEventsEngine.cs
#	GamecraftModdingAPI/Blocks/BlockIDs.cs
#	GamecraftModdingAPI/Blocks/ConsoleBlock.cs
#	GamecraftModdingAPI/Blocks/DampedSpring.cs
#	GamecraftModdingAPI/Blocks/LogicGate.cs
#	GamecraftModdingAPI/Blocks/Motor.cs
#	GamecraftModdingAPI/Blocks/MusicBlock.cs
#	GamecraftModdingAPI/Blocks/ObjectIdentifier.cs
#	GamecraftModdingAPI/Blocks/Piston.cs
#	GamecraftModdingAPI/Blocks/PlacementEngine.cs
#	GamecraftModdingAPI/Blocks/Servo.cs
#	GamecraftModdingAPI/Blocks/SfxBlock.cs
#	GamecraftModdingAPI/Blocks/SpawnPoint.cs
#	GamecraftModdingAPI/Blocks/TextBlock.cs
#	GamecraftModdingAPI/Blocks/Timer.cs
#	GamecraftModdingAPI/GamecraftModdingAPI.csproj
#	GamecraftModdingAPI/Inventory/HotbarEngine.cs
#	GamecraftModdingAPI/Inventory/HotbarSlotSelectionHandlerEnginePatch.cs
#	GamecraftModdingAPI/Main.cs
#	GamecraftModdingAPI/Player.cs
#	GamecraftModdingAPI/Players/PlayerEngine.cs
#	GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
#	TechbloxModdingAPI/BlockGroup.cs
#	TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs
#	TechbloxModdingAPI/Blocks/Engines/RemovalEngine.cs
#	TechbloxModdingAPI/Blocks/Engines/SignalEngine.cs
#	TechbloxModdingAPI/Blueprint.cs
#	TechbloxModdingAPI/Input/FakeInput.cs
2021-12-14 23:26:35 +01:00
e3a7961be4 Made the Game.Enter event only fire once loading finishes and fixed player building mode
Also attempted to fix material changing and updating the rendered block
2021-11-25 01:48:06 +01:00
f53d0b63e7 Fix issues uncovered by the tests
- Fixed the game enter API
- Fixed ToggleTimeMode() placing the player underground by using the full switch animation
- Fixed the menu enter/exit events only firing once due to the game keeping the menu loaded
- Moved everything from AppEngine to GameMenuEngine for consistency
- Reimplemented the Block.Static property, it should actually work again too
- Made the block property test only use blocks placed during the previous test, improved error handling and temporarily disabled testing the Material and the Flipped properties as they cause the game to crash
2021-11-06 04:10:00 +01:00
619a5003cf Update to Techblox 2021.11.03.15.56
Save game details were changed, they may not work properly
Game mode change event no longer sends game data, needs fixing
2021-11-04 20:45:21 +01:00
6204b226d1 Seat events, and everything needed to get there
- Added support for seat enter and exit events and a test for them
- Added support for entering and exiting seat from code
- Changed the Id property of ECS objects to non-abstract, requiring it in the constructor, so that the Player class can inherit EcsObjectBase
- Added a weird constructor to EcsObjectBase that allows running code to determine the object Id
- Added interface for engines that receive entity functions
- Exposed the entity submission scheduler and removed it from FullGameFields because it moved from there
- Made the Game.Enter event only fire after the first entity submission so the game is fully initialized and the local player exists
- Added all seat groups to the dictionary
2021-10-11 01:26:35 +02:00
4bd636b8ed Add wrapped event handler, using the existing ECS object instances
- Added a wrapper class that handles the individual wrapping of event handlers to individually handle exceptions - now it tracks the wrapped event handlers so it can unregister them properly
- Fixed an exception that happened when two ECS objects were created with the same EGID
- Added support for returning an existing ECS object if it exists instead of always creating a new one
- Added a parameter to the entity query extension methods to override the group of the ECS object (could be used for the player properties)
2021-10-08 03:58:01 +02:00
8a03277d84 Added block placement in sim and ECS object tracking
ECS objects are stored in a newly created weak dictionary so that events can be called on them and possibly other things can be done with them
2021-10-02 03:50:20 +02:00
aa947eaba1 Update to Techblox 2021.09.27.15.17
Fixed block name print regex
Made Game.WorkshopId obsolete as it's removed from the game
Fixed removing blocks
2021-10-02 00:01:47 +02:00
63295f82c9 Update to Techblox 2021.09.03.10.36
Removed old dependencies, including uREPL
Added new block IDs
Implemented basic command handling to support existing mod commands
2021-09-07 23:15:03 +02:00
033ebdb86d Fix looking at wires, reduce Wire code
Also added two port name properties directly to the wires
Also added support for converting OptionalRefs to Nullables
2021-09-03 01:30:38 +02:00
2513040343 Add code generator and new block classes
Block classes are generated with all of the properties from the given structs
Properties can be renamed, their name is pulled from TweakableStat attributes if possible
Added support for getting the wire being looked at
2021-08-12 01:11:02 +02:00
77d5e59ef6 Add Motor class 2021-08-12 00:44:23 +02:00
9693341d7a Add block types, run tests, remove unintended properties 2021-08-12 00:34:39 +02:00
c0eae77421 Finish code generator (mostly)
Made the generated members public and final
Removed the comment from the start of the files
Generating the files directly into the project folder
Added comments describing the generated constructors and properties
Using SignalingBlock as a base class
Added support for renaming properties
Added support for getting the name from the tweakable stat name
Added/updated functional block classes
2021-08-11 23:44:26 +02:00
3351993936 Automatically generate properties, fixes, engine class 2021-07-29 01:04:27 +02:00
49c3b60963 Get wire looked at, block class generation 2021-07-29 00:08:57 +02:00
ece71c45a6 Update to Techblox 2021.07.21.16.17 2021-07-22 22:20:53 +02:00
2a1676ce0f Update block ID list 2021-07-01 15:41:58 +02:00
74d5a5c6b1
Fix default values getting changed and add test 2021-06-23 01:58:01 +02:00
76faa69c74 Add support for enabling the screenshot taker, even in sim 2021-06-11 19:51:32 +02:00
52ccbe4dad Fix tests and add new materials 2021-06-10 23:57:06 +02:00
0b2ffef0d3 Update block IDs 2021-06-09 22:03:15 +02:00
99f077a917 Update to Techblox 2021.06.08.16.19
Added check for time mode toggle to avoid crashing the game
Added support for having the ref folder outside the solution in gen_csproj.py
Removed BlockIdentifiers class
Added check for invalid player ID when placing blocks
Resolved compilation errors
2021-06-09 20:11:31 +02:00
c1c226ef2a Added support for setting default color/material and static blocks
Also fixed setting game name/description

When setting the block color or material to default it will look up the default value to use
Blocks can now be set to be static so they don't fall or move at all
2021-06-04 23:07:06 +02:00
NGnius (Graham)
06cb911ea3 Update IMGUI to something roughly TB-like 2021-05-31 17:59:25 -04:00
b31eaa20c0
Check if block type is correct 2021-05-30 02:12:38 +02:00
94c0c1370b
Removed 2 non-OOP classes and fixed fly cam teleport
Remvoed Hotbar and GameClient since their functions are also implemented in OOP classes
Added static methods to add/remove persistent debug info
Made some patches and other things internal
Added support for FlyCams in SetLocation
2021-05-30 01:34:30 +02:00
b8fd14d934 Move speed settings to Player and make it work with players
Probably
2021-05-28 02:52:42 +02:00
5bfd0b7f10 Integrate FlyCam class into Player
Using QueryEntityOptional directly with the player properties
Character structs are camera structs in build mode
The FlyCam rotation is not updated in build mode, only the camera is
2021-05-28 02:12:54 +02:00
220eb02a19
Return descriptions with command names, selected block/color fix 2021-05-25 01:20:46 +02:00
e8515ef42b
Fix events not firing and event exception handling
Copying to Plugins folder on build
Registering deterministic game engines automatically
Each event handler is wrapped so if one fails it will still trigger the rest
2021-05-23 20:53:55 +02:00
f5e3010e48
Removed all obsolete classes and some commented out code 2021-05-21 00:09:36 +02:00
1cbe252727
Move block engines into their own namespace 2021-05-20 23:37:10 +02:00
b3f7dcd36d
Add start of Engine class, removed nonexistent blocks
Not all engine properties are added (yet)
The old block types can be brought back when/if they come back, potentially with different properties
2021-05-20 23:26:22 +02:00
e9df67f462
Use Block.New everywhere, testing *every block property*
Fixed prefab update for nonexistent blocks
Removed Type from block placed/removed event args
Added test to check the block ID enum (whether it has any extra or missing IDs)
Added test to place every block on the ID enum
Added test to set and verify each property of each block type (type-specific properties are also set when they can be through the API)
Added support for enumerator test methods with exception handling
2021-05-19 01:40:15 +02:00
70b322583a
Fix setting the material of a block
Also fixed ID of wood material
2021-05-18 20:00:24 +02:00
4f0645492c
Fix block color and group 2021-05-18 00:44:09 +02:00
58d703f502
Fix block tests and add test command to toggle time mode 2021-05-17 14:55:13 +02:00
NGnius
db08bf1ac0 Fix docs (hopefully) 2021-05-12 20:00:33 -04:00
dd2680abd5
Set the grid scale as well when changing the scale 2021-05-13 01:41:52 +02:00
4807c12387
Fix placing blocks
Most of the removed initialitzers are actually important
Also, the prefab ID was not calculated correctly
Also, the category is 1, not sure why but it is
2021-05-13 00:13:31 +02:00
3432a1ae33
Return block objects based on the group, not a type param
Replaced typeToGroup with GroupToConstructor
The block object's type is determined by the exclusive group instead of a type parameter
Removed the Specialise() method, the API should always return specialised objects

This fixes the not supported exception but not the game crash that follows
2021-05-12 02:33:01 +02:00
7a53e1d32f
Fix command registration 2021-05-12 01:34:40 +02:00
aa12b848d0
Merge branch 'feature-ecs_object_base' 2021-05-12 00:51:56 +02:00
b6b9a29a3c
Convert more things to use EcsObjectBase
Though the major benefit is only for blocks right now (using initializers)
2021-05-12 00:49:01 +02:00
6fedf90380
Remove struct layout stuff
It broke everything using the type
2021-05-12 00:25:07 +02:00
3eef859095
Update gen_csproj script and references 2021-05-11 22:56:36 +02:00
858a5c9b5c
Fix remaining errors, add support for managed entity DB 2021-05-11 00:56:46 +02:00
d238c97906
Remove block info getters and setters
Regex is great

GetBlockInfo\(this, \((\w+) (\w+)\) ?=> ?\2(.+)\);
GetBlockInfo<$1>(this)$3;

SetBlockInfo\(this, \(ref (\w+) (\w+), \w+ (\w+)\) ?=> \2(.*) = \3,\s*value\);
GetBlockInfo<$1>(this)$4 = value;
2021-05-10 23:08:15 +02:00
61184145a9
Start using new extension methods, code cleanup
Removed all of the different block property getter methods
2021-05-10 22:45:07 +02:00
2d99d1d478
Generalize optional references and init data
Added extension methods to query data from ECS objects
Added base class for ECS objects
Added support for representing in-construction ECS objects with an OptionalRef<T>
2021-05-10 02:04:59 +02:00
78ee3b3bcd
Fix block type check on placement 2021-05-10 01:38:15 +02:00
aea3ef3623
Remove AsyncUtils, fix FlyCam and GetThingLookedAt() 2021-05-03 01:25:26 +02:00
62afd3b780
Some file renames that were missing 2021-05-03 00:17:49 +02:00
5172b13b7c
Update readme and version 2021-05-02 02:08:22 +02:00
c914b5b393
Renamed all references of Gamecraft to Techblox
Except those that actually refer to the game's code
2021-05-02 01:56:20 +02:00
a6f52070ee
Rename to TechbloxModdingAPI 2021-05-02 01:08:25 +02:00
807470e289
Add new block types and improve listing them
Now it prints them ordered and mostly suitable to be used in code (it only needs a couple replaces)
2021-05-01 00:38:27 +02:00
df6a2e84e1
Update to Techblox 2021.04.29.18.37 2021-04-30 22:36:54 +02:00
6e03847ab0
FlyCam additions, improve struct
Added property to get the camera from the player
Removed pointer magic
2021-04-27 01:52:54 +02:00
55b38f1678
Start working on FlyCam and create an overcomplicated struct
Just some native code that's totally unnecessary
2021-04-26 03:12:22 +02:00
eb7a09ed22
Fixes, move command patch out of the test class
Removed some command line engines that shouldn't be registered
Fixed registering custom commands - registering it with the existing ones
2021-04-25 02:07:31 +02:00
6a2459b3e7
Attempts to bring console commands back (test) 2021-04-24 03:41:37 +02:00
cc4850a073
Fix fake input 2021-04-20 01:23:39 +02:00
677c8b0907
Add constructor for placing block, remove most PlaceNew args 2021-04-19 19:32:14 +02:00
1f688195af
Add support for flipped blocks and auto-wiring, other fixes 2021-04-19 03:13:00 +02:00
9a4ff858f3
Improve color API and add material API 2021-04-16 01:40:30 +02:00
124ef410c7
Attempt to bring console back and update block ID list 2021-04-13 02:05:16 +02:00
98e00de642
Fix all startup errors 2021-04-12 17:37:51 +02:00
2d41026a05
Turned the rest of the errors into TODOs 2021-04-11 02:36:00 +02:00
a6b69d94c9
Start compatibility with Techblox
Added some TODOs as well
2021-04-10 02:02:47 +02:00
NGnius (Graham)
37e3c6f718 Remove debug FMOD patches 2020-12-28 13:47:08 -05:00
NGnius (Graham)
0ef875b6b2 Document undocumented IMGUI element classes 2020-12-27 18:57:23 -05:00
d954060a5a Add ability to change properties of existing blocks
And not storing custom block data for now
2020-12-27 21:13:49 +01:00
fdc47832f4 Store custom block IDs in save files 2020-12-26 01:59:06 +01:00
NGnius (Graham)
95574a50f8 Merge branch 'master' of https://git.exmods.org/modtainers/GamecraftModdingAPI 2020-12-21 16:57:32 -05:00
NGnius (Graham)
1c014e36ac Add IMGUI styling and initial OOP implementation 2020-12-21 16:31:57 -05:00
879901f4b9 Add new block IDs, a property, 2 tests and fixes 2020-12-20 00:05:02 +01:00
6a90739197 Attempt to use custom cube category 2020-12-19 21:43:49 +01:00
9c5c980c0b Merge pull request 'Add custom block support to the API and update to latest GC version' (#6) from customblocks into master 2020-12-17 21:21:18 +00:00
712ece86db Add custom block registration functionality and a test 2020-12-17 20:20:46 +01:00
a7f6a16231 Update to Gamecraft 2020.12.16.14.19 and custom block stuff
- Fixed the crash on second time start
- Tweaked more stuff about the block

Breaking changes coming from FMOD 2.0:
- Audio[int index] changed to Audio[PARAMETER_ID index]
- Audio.Parameters removed
2020-12-17 02:34:36 +01:00
4e16f251ee Don't use the intended method to create a CubeListData
It adds it with its ID as key but the ID hasn't been set at that point
It works until the second simulation start now
2020-12-13 20:21:46 +01:00
78f0ea0162 Use the intended method to create a CubeListData
The block can be selected but not placed
2020-12-12 23:08:56 +01:00
5dfb01ef0b Use the console block's material again - IT WORKS
It shows up in the inventory but crashes when selected
2020-12-12 16:59:52 +01:00
432d6bcf96 Use the same (physics) componentts and attempt to use custom material 2020-12-12 02:28:42 +01:00
NGnius (Graham)
be7d8ba33a Merge branch 'master' of https://git.exmods.org/modtainers/GamecraftModdingAPI 2020-12-11 12:16:15 -05:00
56a64daa18 Merge branch 'master' into customblocks
# Conflicts:
#	GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
2020-12-11 17:16:05 +01:00
ab1ae51ece Update to Gamecraft 2020.11.30.16.02 2020-12-11 17:11:24 +01:00
NGnius (Graham)
404c47c7c0 Bump version to 1.8.0 2020-11-18 16:46:23 -05:00
fad3b5cbf4 Fix picking block groups... 2020-11-14 22:43:45 +01:00
1f911b1d32 Fix move/rotate during init, add blueprint properties 2020-11-14 18:29:48 +01:00
f30dcd251f Displaying blueprint before placing, enums, ToString()s
Added support for getting the player's current building mode (build, color, config, blueprint)
Added support for getting the current game's mode (building, playing, prefab etc.)
2020-11-14 02:52:16 +01:00
680721256c Add support for copying wires, some fixes and additions
Removing blocks from groups when they are removed from the game
Attempted to update graphics when changing blocks
Disallowing changing the block group after creation, now that we can copy blocks
2020-11-13 23:59:37 +01:00
64b42830a3 Blueprint fixes, bump version, add block copy support
Fixed getting the selected blueprint
Fixed block groups not being assigned to first block
2020-11-13 21:40:32 +01:00
d744aaab79 Add ability to create & move block groups & other stuff
Added a way to store block groups as blueprints
Blocks can be added/removed from block groups, although it doesn't work well atm
Added some patches to the test class in an attempt to debug an unrelated issue
Added a command to test placing a block group
Added a SelectedBlueprint property to the Player class
2020-11-13 17:02:28 +01:00
3dd61b5e4f Replace ToManagedArray() and fix getting blocks from group 2020-11-13 17:02:27 +01:00
1c4e2a0db2 Add support for setting and placing blueprints 2020-11-13 17:02:27 +01:00
4f8feaa24b Add new blocks and some blueprint/block group support 2020-11-13 17:02:27 +01:00
NGnius (Graham)
8eec1358e9 Fix harmony patch error due to fixed name 2020-11-13 17:02:27 +01:00
NGnius (Graham)
08138e3589 Fix build errors from beta hotfix 1 2020-11-13 17:02:27 +01:00
987fbe673a Fix initial issues and add error on patch fail
Fixed compilation and loading issues for 2020.10.27.17.13
2020-11-13 17:01:46 +01:00
4580ae3b66 Add ability to create & move block groups & other stuff
Added a way to store block groups as blueprints
Blocks can be added/removed from block groups, although it doesn't work well atm
Added some patches to the test class in an attempt to debug an unrelated issue
Added a command to test placing a block group
Added a SelectedBlueprint property to the Player class
2020-11-12 02:39:58 +01:00
f1376f5df6 Replace ToManagedArray() and fix getting blocks from group 2020-11-10 23:08:27 +01:00
2179ba6386 Add support for setting and placing blueprints 2020-11-10 19:28:36 +01:00
1a986056a1 Add new blocks and some blueprint/block group support 2020-11-10 16:37:20 +01:00
NGnius (Graham)
d891f12701 Fix harmony patch error due to fixed name 2020-11-09 16:33:12 -05:00
NGnius (Graham)
1cb663b4d1 Fix build errors from beta hotfix 1 2020-11-09 16:18:25 -05:00
0bd348bd47
Fix initial issues and add error on patch fail
Fixed compilation and loading issues for 2020.10.27.17.13
2020-10-29 00:37:47 +01:00
3929144171
Merge remote-tracking branch 'origin/master' into preview
# Conflicts:
#	GamecraftModdingAPI/Block.cs
#	GamecraftModdingAPI/GamecraftModdingAPI.csproj
2020-10-28 21:10:30 +01:00
NGnius (Graham)
c6a1ea35cc Add damped spring 2020-10-27 11:59:21 -04:00
b0b496f22f Fix ConcurrentModificationException and some attempts 2020-10-22 02:34:59 +02:00
4701b3577d Make BlockColor.Index a property and other fixes 2020-10-02 17:06:06 +02:00
abbb83da26 Chunk and cluster fixes and improvements & bump version
Added Cluster.GetSimBodies() and SimBody.GetBlocks()
Fixed some issues with IDs and bad handling of them
2020-10-02 16:40:06 +02:00
64aace3bde Remove ScalingEngine.Setup() and add object ID to dict 2020-10-02 14:52:37 +02:00
9e9f56881f Add hotfix blocks and Player.LocalPlayer 2020-10-02 14:52:37 +02:00
c9e71d84b4 Add support for getting the RGB of block colors
Only works if the constructors are used
2020-10-02 14:52:37 +02:00
NGnius (Graham)
4dfa7b0f4e Implement SFX block API and bump version 2020-10-02 14:52:33 +02:00
1a0c98dd67 Add the rest of the blocks 2020-10-02 14:52:26 +02:00
f2ce037564 Fix TextBlock.Text=null, most new blocks and others 2020-10-02 14:52:26 +02:00
92965404ce Remove ScalingEngine.Setup() and add object ID to dict 2020-10-02 01:54:59 +02:00
58cfba443e Add hotfix blocks and Player.LocalPlayer 2020-09-30 23:52:17 +02:00
ee6a0e3af6 Add support for getting the RGB of block colors
Only works if the constructors are used
2020-09-28 03:10:59 +02:00
NGnius (Graham)
9e6edc19bd Implement SFX block API and bump version 2020-09-23 15:31:54 -04:00
d581ec598a Add the rest of the blocks 2020-09-19 00:13:05 +02:00
1e9d1c8f81 Fix TextBlock.Text=null, most new blocks and others 2020-09-18 21:19:39 +02:00
53bdd27166 Merge master into preview 2020-09-18 17:10:01 +02:00
c06ed340a2 Using the console block's material
Progressed a lot
2020-09-17 23:08:26 +02:00
f295f712b6 Merge branch 'master' into customblocks
# Conflicts:
#	GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
2020-09-17 19:18:00 +02:00
NGnius (Graham)
aae2057972 Convert relevant blocks to wireable blocks and fix wire connect during block init 2020-08-23 09:59:13 -04:00
NGnius (Graham)
daf4a24bc9 Fix namespace build error from unused using statement (I deleted it) 2020-08-22 09:26:51 -04:00
NGnius (Graham)
11b94e384e Update refs 2020-08-22 09:25:14 -04:00
cfdc5e8c26 Fixes, block IDs, cluster & chunk health support 2020-08-22 09:24:18 -04:00
NGnius (Graham)
fd97194903 Fix build issues for latest Gamecraft preview version 2020-08-22 09:23:59 -04:00
2172364d26 Fixes, block IDs, cluster & chunk health support 2020-08-13 16:59:13 +02:00
NGnius (Graham)
89f354b647 Fix Game Over detection 2020-08-13 10:12:36 -04:00
NGnius (Graham)
50ebf4f0a6 Fix build issues for latest Gamecraft preview version 2020-08-07 13:55:00 -04:00
NGnius (Graham)
167ea5388b Merge branch 'master' into preview 2020-08-07 12:23:16 -04:00
NGnius (Graham)
8354123169 Cache additional info to avoid entity queries 2020-08-07 12:05:49 -04:00
NGnius (Graham)
7f5a36cb62 Automate version bumping because I keep forgetting doxygen.conf 2020-08-04 15:10:07 -04:00
NGnius (Graham)
e56871f5ef Fix wire entity queries when its not submitted yet 2020-08-03 13:24:35 -04:00
NGnius (Graham)
708dbdd81d Add wiring API and improve signal support 2020-08-03 12:45:38 -04:00
NGnius (Graham)
ca0e6e089d Mark old event system as deprecated 2020-08-03 12:43:00 -04:00
NGnius (Graham)
b81562ea58 Fix sfx block test default value 2020-07-25 12:12:48 -04:00
057a030c20 Update music block and attempt to fix test 2020-07-24 11:11:53 -04:00
15485481a2 Add some info and prev. value for setters 2020-07-24 11:11:53 -04:00
b53dff5d12 Remove initializer data once the block is placed 2020-07-24 11:11:53 -04:00
5264d98ce7 Test fixes, block event Block property
Fixed Assert.Equal()
Changed tests to reflect changes
Added Block property to the block event args
Completely removed sync things
2020-07-24 11:11:53 -04:00
5e335e78ff Implement init for position and rotation 2020-07-24 11:11:52 -04:00
7336fe8353 Add support for initializing blocks with properties
Newly created blocks use the initializer to set properties, allowing the user to set per-block properties
2020-07-24 11:11:52 -04:00
89d32956d9 Automatically invoke the correct block constructor
And store delegates of dynamic methods invoking constructors
Tested with the automated tests
2020-07-24 11:11:52 -04:00
NGnius (Graham)
ea8a9184bc Add popup UI method to Client 2020-07-24 11:11:52 -04:00
NGnius (Graham)
926d968eed Add sfx block support 2020-07-24 11:11:48 -04:00
NGnius (Graham)
421faf7167 Improve dev info in README 2020-07-24 11:10:20 -04:00
47126d2d79
Update music block and attempt to fix test 2020-07-21 02:36:11 +02:00
c5e9599c46
Merge branch 'delegating' into preview 2020-07-21 00:24:50 +02:00
3f2139d592
Add some info and prev. value for setters 2020-07-21 00:19:30 +02:00
NGnius (Graham)
9e47bbcd9a Add popup UI method to Client 2020-07-19 20:05:01 -04:00
NGnius (Graham)
cda57afade Add sfx block support 2020-07-19 16:39:35 -04:00
NGnius (Graham)
4a9ceecc29 Improve dev info in README 2020-07-19 12:43:06 -04:00
16521ab7eb Remove initializer data once the block is placed 2020-07-19 01:42:32 +02:00
cc4ed3e174 Test fixes, block event Block property
Fixed Assert.Equal()
Changed tests to reflect changes
Added Block property to the block event args
Completely removed sync things
2020-07-19 01:13:39 +02:00
d842df7681 Implement init for position and rotation 2020-07-15 22:46:48 +02:00
3592c6f464 Add support for initializing blocks with properties
Newly created blocks use the initializer to set properties, allowing the user to set per-block properties
2020-07-15 21:58:24 +02:00
5bbb54c0c5 Automatically invoke the correct block constructor
And store delegates of dynamic methods invoking constructors
Tested with the automated tests
2020-07-13 21:55:48 +02:00
9b1e2548d1 Attempts to create custom block types
It can load certain assets (a Cube from a sample) but fails because of missing shaders
My own Cube doesn't even get that far
2020-06-14 21:40:47 +02:00
189 changed files with 11986 additions and 7483 deletions

67
Automation/bump_version.py Executable file
View file

@ -0,0 +1,67 @@
#!/usr/bin/python3
import argparse
import re
# this assumes a mostly semver-complient version number
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Increment GamecraftModdingAPI version")
parser.add_argument('version', metavar="VN", type=str, help="The version number to increment, or the index of the number (zero-indexed).")
args = parser.parse_args()
version_index = -1
try:
version_index = int(args.version)
except Exception:
if args.version.lower() == "major":
version_index = 0
elif args.version.lower() == "minor":
version_index = 1
elif args.version.lower() == "patch":
version_index = 2
if version_index < 0:
print("Could not parse version argument.")
exit(version_index)
print(version_index)
old_version = ""
new_version = ""
with open("../GamecraftModdingAPI/GamecraftModdingAPI.csproj", "r") as xmlFile:
print("Parsing GamecraftModdingAPI.csproj")
fileStr = xmlFile.read()
versionMatch = re.search(r"<Version>(.+)</Version>", fileStr)
if versionMatch is None:
print("Unable to find version number in GamecraftModdingAPI.csproj")
exit(1)
old_version = versionMatch.group(1)
versionList = old_version.split(".")
if len(versionList) <= version_index:
print("Invalid version string")
exit(1)
versionList[version_index] = str(int(versionList[version_index]) + 1)
for i in range(version_index + 1, len(versionList)):
try:
int(versionList[i])
versionList[i] = "0"
except Exception:
tmp = versionList[i].split("-")
tmp[0] = "0"
versionList[i] = "-".join(tmp)
new_version = ".".join(versionList)
print(new_version)
newFileContents = fileStr.replace("<Version>"+old_version+"</Version>", "<Version>"+new_version+"</Version>")
with open("../GamecraftModdingAPI/GamecraftModdingAPI.csproj", "w") as xmlFile:
print("Writing new version to project file")
xmlFile.write(newFileContents)
with open("../doxygen.conf", "r") as doxFile:
print("Parsing doxygen.conf")
doxStr = doxFile.read()
newFileContents = doxStr.replace("= \"v" + old_version + "\"", "= \"v" + new_version + "\"")
with open("../doxygen.conf", "w") as doxFile:
print("Writing new version to doxygen config")
doxFile.write(newFileContents)

19
Automation/gen_csproj.py Normal file → Executable file
View file

@ -3,15 +3,22 @@
import argparse
from pathlib import Path, PurePath
import re
import os
DLL_EXCLUSIONS_REGEX = r"(System|Microsoft|Mono|IronPython|DiscordRPC)\."
def getAssemblyReferences(path):
asmDir = Path(path)
result = list()
addedPath = ""
if not asmDir.exists():
addedPath = "../"
asmDir = Path(addedPath + path)
for child in asmDir.iterdir():
if child.is_file() and re.search(DLL_EXCLUSIONS_REGEX, str(child), re.I) is None and str(child).lower().endswith(".dll"):
result.append(str(child).replace("\\", "/"))
childstr = str(child)
childstr = os.path.relpath(childstr, addedPath).replace("\\", "/")
result.append(childstr)
return result
def buildReferencesXml(path):
@ -27,16 +34,16 @@ def buildReferencesXml(path):
return "<!--Start Dependencies-->\n <ItemGroup>\n" + "".join(result) + " </ItemGroup>\n<!--End Dependencies-->"
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate GamecraftModdingAPI.csproj")
parser = argparse.ArgumentParser(description="Generate TechbloxModdingAPI.csproj")
# TODO (maybe?): add params for custom csproj read and write locations
args = parser.parse_args()
print("Building Assembly references")
asmXml = buildReferencesXml("../ref/GamecraftPreview_Data/Managed")
asmXml = buildReferencesXml("../ref_preview/TechbloxPreview_Data/Managed")
# print(asmXml)
with open("../GamecraftModdingAPI/GamecraftModdingAPI.csproj", "r") as xmlFile:
print("Parsing GamecraftModdingAPI.csproj")
with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "r") as xmlFile:
print("Parsing TechbloxModdingAPI.csproj")
fileStr = xmlFile.read()
# print(fileStr)
depsStart = re.search(r"\<!--\s*Start\s+Dependencies\s*--\>", fileStr)
@ -45,7 +52,7 @@ if __name__ == "__main__":
print("Unable to find dependency XML comments, aborting!")
exit(1)
newFileStr = fileStr[:depsStart.start()] + "\n" + asmXml + "\n" + fileStr[depsEnd.end() + 1:]
with open("../GamecraftModdingAPI/GamecraftModdingAPI.csproj", "w") as xmlFile:
with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "w") as xmlFile:
print("Writing Assembly references")
xmlFile.write(newFileStr)
# print(newFileStr)

View file

@ -0,0 +1,142 @@
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Gamecraft.Tweaks;
using RobocraftX.Common;
using Svelto.ECS;
using Techblox.EngineBlock;
namespace CodeGenerator
{
public class BlockClassGenerator
{
public void Generate(string name, string group = null, Dictionary<string, string> renames = null, params Type[] types)
{
if (group is null)
{
group = GetGroup(name) + "_BLOCK_GROUP";
if (typeof(CommonExclusiveGroups).GetFields().All(field => field.Name != group))
group = GetGroup(name) + "_BLOCK_BUILD_GROUP";
}
if (!group.Contains("."))
group = "CommonExclusiveGroups." + group;
var codeUnit = new CodeCompileUnit();
var ns = new CodeNamespace("TechbloxModdingAPI.Blocks");
ns.Imports.Add(new CodeNamespaceImport("RobocraftX.Common"));
ns.Imports.Add(new CodeNamespaceImport("Svelto.ECS"));
var cl = new CodeTypeDeclaration(name);
//cl.BaseTypes.Add(baseClass != null ? new CodeTypeReference(baseClass) : new CodeTypeReference("Block"));
cl.BaseTypes.Add(new CodeTypeReference("SignalingBlock"));
cl.Members.Add(new CodeConstructor
{
Parameters = {new CodeParameterDeclarationExpression("EGID", "egid")},
Comments =
{
_start, new CodeCommentStatement($"Constructs a(n) {name} object representing an existing block.", true), _end
},
BaseConstructorArgs = {new CodeVariableReferenceExpression("egid")},
Attributes = MemberAttributes.Public | MemberAttributes.Final
});
cl.Members.Add(new CodeConstructor
{
Parameters =
{
new CodeParameterDeclarationExpression(typeof(uint), "id")
},
Comments =
{
_start, new CodeCommentStatement($"Constructs a(n) {name} object representing an existing block.", true), _end
},
BaseConstructorArgs =
{
new CodeObjectCreateExpression("EGID", new CodeVariableReferenceExpression("id"),
new CodeVariableReferenceExpression(group))
},
Attributes = MemberAttributes.Public | MemberAttributes.Final
});
foreach (var type in types)
{
GenerateProperties(cl, type, name, renames);
}
ns.Types.Add(cl);
codeUnit.Namespaces.Add(ns);
var provider = CodeDomProvider.CreateProvider("CSharp");
var path = $@"..\..\..\TechbloxModdingAPI\Blocks\{name}.cs";
using (var sw = new StreamWriter(path))
{
provider.GenerateCodeFromCompileUnit(codeUnit, sw, new CodeGeneratorOptions {BracingStyle = "C"});
}
File.WriteAllLines(path,
File.ReadAllLines(path).SkipWhile(line => line.StartsWith("//") || line.Length == 0));
}
private static string GetGroup(string name)
{
var ret = "";
foreach (var ch in name)
{
if (char.IsUpper(ch) && ret.Length > 0)
ret += "_" + ch;
else
ret += char.ToUpper(ch);
}
return ret;
}
private void GenerateProperties(CodeTypeDeclaration cl, Type type, string baseClass,
Dictionary<string, string> renames)
{
if (!typeof(IEntityComponent).IsAssignableFrom(type))
throw new ArgumentException("Type must be an entity component");
foreach (var field in type.GetFields())
{
var attr = field.GetCustomAttribute<TweakableStatAttribute>();
if (renames == null || !renames.TryGetValue(field.Name, out var propName))
{
propName = field.Name;
if (attr != null)
propName = attr.propertyName;
}
propName = char.ToUpper(propName[0]) + propName.Substring(1);
var structFieldReference = new CodeFieldReferenceExpression(new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(new CodeSnippetExpression("BlockEngine"),
"GetBlockInfo", new CodeTypeReference(type)),
new CodeThisReferenceExpression()), field.Name);
cl.Members.Add(new CodeMemberProperty
{
Name = propName,
HasGet = true,
HasSet = true,
GetStatements =
{
new CodeMethodReturnStatement(structFieldReference)
},
SetStatements =
{
new CodeAssignStatement(structFieldReference, new CodePropertySetValueReferenceExpression())
},
Type = new CodeTypeReference(field.FieldType),
Attributes = MemberAttributes.Public | MemberAttributes.Final,
Comments =
{
_start, new CodeCommentStatement($"Gets or sets the {baseClass}'s {propName} property." +
$" {(attr != null ? "Tweakable stat." : "May not be saved.")}", true), _end
}
});
}
}
private static readonly CodeCommentStatement _start = new CodeCommentStatement("<summary>", true);
private static readonly CodeCommentStatement _end = new CodeCommentStatement("</summary>", true);
}
}

File diff suppressed because it is too large Load diff

42
CodeGenerator/Program.cs Normal file
View file

@ -0,0 +1,42 @@
using System.Collections.Generic;
using RobocraftX.Blocks;
using RobocraftX.PilotSeat;
using Techblox.EngineBlock;
using Techblox.WheelRigBlock;
namespace CodeGenerator
{
internal class Program
{
public static void Main(string[] args)
{
var bcg = new BlockClassGenerator();
bcg.Generate("Engine", null, new Dictionary<string, string>
{
{ "engineOn", "On" }
}, typeof(EngineBlockComponent), // Simulation time properties
typeof(EngineBlockTweakableComponent), typeof(EngineBlockReadonlyComponent));
bcg.Generate("DampedSpring", "DAMPEDSPRING_BLOCK_GROUP", new Dictionary<string, string>
{
{"maxExtent", "MaxExtension"}
},
typeof(TweakableJointDampingComponent), typeof(DampedSpringReadOnlyStruct));
bcg.Generate("LogicGate", "LOGIC_BLOCK_GROUP");
bcg.Generate("Servo", types: typeof(ServoReadOnlyStruct), renames: new Dictionary<string, string>
{
{"minDeviation", "MinimumAngle"},
{"maxDeviation", "MaximumAngle"},
{"servoVelocity", "MaximumForce"}
});
bcg.Generate("WheelRig", "WHEELRIG_BLOCK_BUILD_GROUP", null,
typeof(WheelRigTweakableStruct), typeof(WheelRigReadOnlyStruct),
typeof(WheelRigSteerableTweakableStruct), typeof(WheelRigSteerableReadOnlyStruct));
bcg.Generate("Seat", "RobocraftX.PilotSeat.SeatGroups.PILOTSEAT_BLOCK_BUILD_GROUP", null, typeof(SeatFollowCamComponent), typeof(SeatReadOnlySettingsComponent));
bcg.Generate("Piston", null, new Dictionary<string, string>
{
{"pistonVelocity", "MaximumForce"}
}, typeof(PistonReadOnlyStruct));
bcg.Generate("Motor", null, null, typeof(MotorReadOnlyStruct));
}
}
}

View file

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CodeGenerator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CodeGenerator")]
[assembly: AssemblyCopyright("Copyright © ExMods 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0EBB6400-95A7-4A3D-B2ED-BF31E364CC10")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -1,63 +0,0 @@
using System;
using RobocraftX.GUI.MyGamesScreen;
using RobocraftX.GUI;
using Svelto.ECS;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.App
{
public class AppEngine : IFactoryEngine
{
public event EventHandler<MenuEventArgs> EnterMenu;
public event EventHandler<MenuEventArgs> ExitMenu;
public IEntityFactory Factory { set; private get; }
public string Name => "GamecraftModdingAPIAppEngine";
public bool isRemovable => false;
public EntitiesDB entitiesDB { set; private get; }
public void Dispose()
{
IsInMenu = false;
ExceptionUtil.InvokeEvent(ExitMenu, this, new MenuEventArgs { });
}
public void Ready()
{
IsInMenu = true;
ExceptionUtil.InvokeEvent(EnterMenu, this, new MenuEventArgs { });
}
// app functionality
public bool IsInMenu
{
get;
private set;
} = false;
public Game[] GetMyGames()
{
EntityCollection<MyGameDataEntityStruct> mgsevs = entitiesDB.QueryEntities<MyGameDataEntityStruct>(MyGamesScreenExclusiveGroups.MyGames);
Game[] games = new Game[mgsevs.count];
for (int i = 0; i < mgsevs.count; i++)
{
Utility.Logging.MetaDebugLog($"Found game named {mgsevs[i].GameName}");
games[i] = new Game(mgsevs[i].ID);
}
return games;
}
}
public struct MenuEventArgs
{
}
}

View file

@ -1,82 +0,0 @@
using System;
using UnityEngine;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.App
{
/// <summary>
/// The Gamecraft application that is running this code right now.
/// </summary>
public class Client
{
// extensible engine
protected static AppEngine appEngine = new AppEngine();
/// <summary>
/// An event that fires whenever the main menu is loaded.
/// </summary>
public static event EventHandler<MenuEventArgs> EnterMenu
{
add => appEngine.EnterMenu += value;
remove => appEngine.EnterMenu -= value;
}
/// <summary>
/// An event that fire whenever the main menu is exited.
/// </summary>
public static event EventHandler<MenuEventArgs> ExitMenu
{
add => appEngine.ExitMenu += value;
remove => appEngine.ExitMenu -= value;
}
/// <summary>
/// Gamecraft build version string.
/// Usually this is in the form YYYY.mm.DD.HH.MM.SS
/// </summary>
/// <value>The version.</value>
public string Version
{
get => Application.version;
}
/// <summary>
/// Unity version string.
/// </summary>
/// <value>The unity version.</value>
public string UnityVersion
{
get => Application.unityVersion;
}
/// <summary>
/// Game saves currently visible in the menu.
/// These take a second to completely populate after the EnterMenu event fires.
/// </summary>
/// <value>My games.</value>
public Game[] MyGames
{
get
{
if (!appEngine.IsInMenu) return new Game[0];
return appEngine.GetMyGames();
}
}
/// <summary>
/// Whether Gamecraft is in the Main Menu
/// </summary>
/// <value><c>true</c> if in menu; <c>false</c> when loading or in a game.</value>
public bool InMenu
{
get => appEngine.IsInMenu;
}
internal static void Init()
{
MenuEngineManager.AddMenuEngine(appEngine);
}
}
}

View file

@ -1,119 +0,0 @@
using System;
using System.Collections.Generic;
using HarmonyLib;
using RobocraftX;
using RobocraftX.Common;
using RobocraftX.Schedulers;
using RobocraftX.SimulationModeState;
using Svelto.ECS;
using Svelto.Tasks;
using Svelto.Tasks.Lean;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.App
{
public class GameGameEngine : IApiEngine
{
public event EventHandler<GameEventArgs> EnterGame;
public event EventHandler<GameEventArgs> ExitGame;
public string Name => "GamecraftModdingAPIGameInfoMenuEngine";
public bool isRemovable => false;
public EntitiesDB entitiesDB { set; private get; }
public void Dispose()
{
ExceptionUtil.InvokeEvent(ExitGame, this, new GameEventArgs { GameName = GameMode.SaveGameDetails.Name, GamePath = GameMode.SaveGameDetails.Folder });
IsInGame = false;
}
public void Ready()
{
ExceptionUtil.InvokeEvent(EnterGame, this, new GameEventArgs { GameName = GameMode.SaveGameDetails.Name, GamePath = GameMode.SaveGameDetails.Folder });
IsInGame = true;
}
// game functionality
public bool IsInGame
{
get;
private set;
} = false;
public void ExitCurrentGame(bool async = false)
{
if (async)
{
ExitCurrentGameAsync().RunOn(Lean.EveryFrameStepRunner_RUNS_IN_TIME_STOPPED_AND_RUNNING);
}
else
{
entitiesDB.QueryEntity<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID).WantsToQuit = true;
entitiesDB.PublishEntityChange<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
}
}
public IEnumerator<TaskContract> ExitCurrentGameAsync()
{
/*
while (Lean.EveryFrameStepRunner_RUNS_IN_TIME_STOPPED_AND_RUNNING.isStopping) { yield return Yield.It; }
AccessTools.Method(typeof(FullGameCompositionRoot), "SwitchToMenu").Invoke(FullGameFields.Instance, new object[0]);*/
yield return Yield.It;
entitiesDB.QueryEntity<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID).WantsToQuit = true;
entitiesDB.PublishEntityChange<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
}
public void SaveCurrentGame()
{
ref GameSceneEntityStruct gses = ref entitiesDB.QueryEntity<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
gses.LoadAfterSaving = false;
gses.SaveNow = true;
entitiesDB.PublishEntityChange<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
}
public bool IsTimeRunningMode()
{
return TimeRunningModeUtil.IsTimeRunningMode(entitiesDB);
}
public bool IsTimeStoppedMode()
{
return TimeRunningModeUtil.IsTimeStoppedMode(entitiesDB);
}
public void ToggleTimeMode()
{
TimeRunningModeUtil.ToggleTimeRunningState(entitiesDB);
}
public EGID[] GetAllBlocksInGame(BlockIDs filter = BlockIDs.Invalid)
{
var allBlocks = entitiesDB.QueryEntities<DBEntityStruct>();
List<EGID> blockEGIDs = new List<EGID>();
if (filter == BlockIDs.Invalid)
{
foreach (var (blocks, _) in allBlocks)
foreach (var block in blocks)
blockEGIDs.Add(block.ID);
return blockEGIDs.ToArray();
}
else
{
foreach (var (blocks, _) in allBlocks)
foreach (var block in blocks)
if (block.DBID == (ulong) filter)
blockEGIDs.Add(block.ID);
return blockEGIDs.ToArray();
}
}
}
}

View file

@ -1,128 +0,0 @@
using System;
using HarmonyLib;
using RobocraftX;
using RobocraftX.Common;
using RobocraftX.GUI;
using RobocraftX.GUI.MyGamesScreen;
using Svelto.ECS;
using Svelto.ECS.Experimental;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.App
{
public class GameMenuEngine : IFactoryEngine
{
public IEntityFactory Factory { set; private get; }
public string Name => "GamecraftModdingAPIGameInfoGameEngine";
public bool isRemovable => false;
public EntitiesDB entitiesDB { set; private get; }
public void Dispose()
{
IsInMenu = false;
}
public void Ready()
{
IsInMenu = true;
}
// game functionality
public bool IsInMenu
{
get;
private set;
} = false;
public bool CreateMyGame(EGID id, string path = "", uint thumbnailId = 0, string gameName = "", string creatorName = "", string description = "", long createdDate = 0L)
{
EntityComponentInitializer eci = Factory.BuildEntity<MyGameDataEntityDescriptor_DamnItFJWhyDidYouMakeThisInternal>(id);
eci.Init(new MyGameDataEntityStruct
{
SavedGamePath = new ECSString(path),
ThumbnailId = thumbnailId,
GameName = new ECSString(gameName),
CreatorName = new ECSString(creatorName),
GameDescription = new ECSString(description),
CreatedDate = createdDate,
});
// entitiesDB.PublishEntityChange<MyGameDataEntityStruct>(id); // this will always fail
return true;
}
public uint HighestID()
{
EntityCollection<MyGameDataEntityStruct> games = entitiesDB.QueryEntities<MyGameDataEntityStruct>(MyGamesScreenExclusiveGroups.MyGames);
uint max = 0;
for (int i = 0; i < games.count; i++)
{
if (games[i].ID.entityID > max)
{
max = games[i].ID.entityID;
}
}
return max;
}
public bool EnterGame(EGID id)
{
if (!ExistsGameInfo(id)) return false;
ref MyGameDataEntityStruct mgdes = ref GetGameInfo(id);
return EnterGame(mgdes.GameName, mgdes.SavedGamePath);
}
public bool EnterGame(string gameName, string path, ulong workshopId = 0uL, bool autoEnterSim = false)
{
GameMode.CurrentMode = autoEnterSim ? RCXMode.Play : RCXMode.Build;
GameMode.SaveGameDetails = new SaveGameDetails(gameName, path, workshopId);
// the private FullGameCompositionRoot.SwitchToGame() method gets passed to menu items for this reason
AccessTools.Method(typeof(FullGameCompositionRoot), "SwitchToGame").Invoke(FullGameFields.Instance, new object[0]);
return true;
}
public bool SetGameName(EGID id, string name)
{
if (!ExistsGameInfo(id)) return false;
GetGameInfo(id).GameName.Set(name);
GetGameViewInfo(id).MyGamesSlotComponent.GameName = StringUtil.SanitiseString(name);
return true;
}
public bool SetGameDescription(EGID id, string name)
{
if (!ExistsGameInfo(id)) return false;
GetGameInfo(id).GameDescription.Set(name);
GetGameViewInfo(id).MyGamesSlotComponent.GameDescription = StringUtil.SanitiseString(name);
return true;
}
public bool ExistsGameInfo(EGID id)
{
return entitiesDB.Exists<MyGameDataEntityStruct>(id);
}
public ref MyGameDataEntityStruct GetGameInfo(EGID id)
{
return ref GetComponent<MyGameDataEntityStruct>(id);
}
public ref MyGamesSlotEntityViewStruct GetGameViewInfo(EGID id)
{
return ref GetComponent<MyGamesSlotEntityViewStruct>(new EGID(id.entityID, MyGamesScreenExclusiveGroups.GameSlotGuiEntities));
}
public ref T GetComponent<T>(EGID id) where T: struct, IEntityComponent
{
return ref entitiesDB.QueryEntity<T>(id);
}
}
internal class MyGameDataEntityDescriptor_DamnItFJWhyDidYouMakeThisInternal : GenericEntityDescriptor<MyGameDataEntityStruct> { }
}

View file

@ -1,26 +0,0 @@
using System;
using System.Reflection;
using RobocraftX.CR.MainGame;
using RobocraftX.StateSync;
using HarmonyLib;
namespace GamecraftModdingAPI.App
{
[HarmonyPatch]
class StateSyncRegPatch
{
public static void Postfix(StateSyncRegistrationHelper stateSyncReg)
{
// register sim/build events engines
Game.InitDeterministic(stateSyncReg);
}
[HarmonyTargetMethod]
public static MethodBase Target()
{
return AccessTools.Method(typeof(MainGameCompositionRoot), "DeterministicCompose").MakeGenericMethod(typeof(object));
}
}
}

View file

@ -1,369 +0,0 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using RobocraftX.Common;
using RobocraftX.Blocks;
using Unity.Mathematics;
using Unity.Entities;
using Gamecraft.Blocks.GUI;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI
{
/// <summary>
/// A single (perhaps scaled) block. Properties may return default values if the block is removed and then setting them is ignored.
/// For specific block type operations, use the specialised block classes in the GamecraftModdingAPI.Blocks namespace.
/// </summary>
public class Block : IEquatable<Block>, IEquatable<EGID>
{
protected static readonly PlacementEngine PlacementEngine = new PlacementEngine();
protected static readonly MovementEngine MovementEngine = new MovementEngine();
protected static readonly RotationEngine RotationEngine = new RotationEngine();
protected static readonly RemovalEngine RemovalEngine = new RemovalEngine();
protected static readonly SignalEngine SignalEngine = new SignalEngine();
protected static readonly BlockEventsEngine BlockEventsEngine = new BlockEventsEngine();
protected static readonly ScalingEngine ScalingEngine = new ScalingEngine();
protected internal static readonly BlockEngine BlockEngine = new BlockEngine();
/// <summary>
/// Place a new block at the given position. If scaled, position means the center of the block. The default block size is 0.2 in terms of position.
/// Place blocks next to each other to connect them.
/// The placed block will be a complete block with a placement grid and collision which will be saved along with the game.
/// <para></para>
/// <para>When placing multiple blocks, do not access properties immediately after creation as this
/// triggers a sync each time which can affect performance and may cause issues with the game.
/// You may either use AsyncUtils.WaitForSubmission() after placing all of the blocks
/// or simply access the block properties which will trigger the synchronization the first time a property is used.</para>
/// </summary>
/// <param name="block">The block's type</param>
/// <param name="color">The block's color</param>
/// <param name="darkness">The block color's darkness (0-9) - 0 is default color</param>
/// <param name="position">The block's position in the grid - default block size is 0.2</param>
/// <param name="rotation">The block's rotation in degrees</param>
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
/// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
/// <param name="player">The player who placed the block</param>
/// <returns>The placed block or null if failed</returns>
public static Block PlaceNew(BlockIDs block, float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
return new Block(PlacementEngine.PlaceBlock(block, color, darkness,
position, uscale, scale, player, rotation));
}
return null;
}
/// <summary>
/// Place a new block at the given position. If scaled, position means the center of the block. The default block size is 0.2 in terms of position.
/// Place blocks next to each other to connect them.
/// The placed block will be a complete block with a placement grid and collision which will be saved along with the game.
/// <para></para>
/// <para>This method waits for the block to be constructed in the game which may take a significant amount of time.
/// Only use this to place a single block.
/// For placing multiple blocks, use PlaceNew() then AsyncUtils.WaitForSubmission() when done with placing blocks.</para>
/// </summary>
/// <param name="block">The block's type</param>
/// <param name="color">The block's color</param>
/// <param name="darkness">The block color's darkness (0-9) - 0 is default color</param>
/// <param name="position">The block's position in the grid - default block size is 0.2</param>
/// <param name="rotation">The block's rotation in degrees</param>
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
/// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
/// <param name="player">The player who placed the block</param>
/// <returns>The placed block or null if failed</returns>
public static async Task<Block> PlaceNewAsync(BlockIDs block, float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
try
{
var ret = new Block(PlacementEngine.PlaceBlock(block, color, darkness,
position, uscale, scale, player, rotation));
await AsyncUtils.WaitForSubmission();
return ret;
}
catch (Exception e)
{
Logging.MetaDebugLog(e);
}
}
return null;
}
/// <summary>
/// Returns the most recently placed block.
/// </summary>
/// <returns>The block object</returns>
public static Block GetLastPlacedBlock()
{
return new Block(BlockIdentifiers.LatestBlockID);
}
/// <summary>
/// An event that fires each time a block is placed.
/// </summary>
public static event EventHandler<BlockPlacedRemovedEventArgs> Placed
{
add => BlockEventsEngine.Placed += value;
remove => BlockEventsEngine.Placed -= value;
}
/// <summary>
/// An event that fires each time a block is removed.
/// </summary>
public static event EventHandler<BlockPlacedRemovedEventArgs> Removed
{
add => BlockEventsEngine.Removed += value;
remove => BlockEventsEngine.Removed -= value;
}
public Block(EGID id)
{
Id = id;
}
/// <summary>
/// This overload searches for the correct group the block is in.
/// It will throw an exception if the block doesn't exist.
/// Use the EGID constructor where possible or subclasses of Block as those specify the group.
/// </summary>
public Block(uint id)
{
Id = BlockEngine.FindBlockEGID(id) ?? throw new BlockTypeException("Could not find the appropriate group for the block. The block probably doesn't exist or hasn't been submitted.");
}
public EGID Id { get; }
/// <summary>
/// The block's current position or zero if the block no longer exists.
/// A block is 0.2 wide by default in terms of position.
/// </summary>
public float3 Position
{
get => Exists ? MovementEngine.GetPosition(Id) : float3.zero;
set
{
if (Exists) MovementEngine.MoveBlock(Id, value);
}
}
/// <summary>
/// The block's current rotation in degrees or zero if the block doesn't exist.
/// </summary>
public float3 Rotation
{
get => Exists ? RotationEngine.GetRotation(Id) : float3.zero;
set
{
if (Exists) RotationEngine.RotateBlock(Id, value);
}
}
/// <summary>
/// The block's non-uniform scale or zero if the block's invalid. Independent of the uniform scaling.
/// The default scale of 1 means 0.2 in terms of position.
/// </summary>
public float3 Scale
{
get => BlockEngine.GetBlockInfo<ScalingEntityStruct>(Id).scale;
set
{
if (!Exists) return; //UpdateCollision needs the block to exist
ref var scaling = ref BlockEngine.GetBlockInfo<ScalingEntityStruct>(Id);
scaling.scale = value;
ScalingEngine.UpdateCollision(Id);
}
}
/// <summary>
/// The block's uniform scale or zero if the block's invalid. Also sets the non-uniform scale.
/// The default scale of 1 means 0.2 in terms of position.
/// </summary>
public int UniformScale
{
get => BlockEngine.GetBlockInfo<UniformBlockScaleEntityStruct>(Id).scaleFactor;
set
{
ref var scaleStruct = ref BlockEngine.GetBlockInfo<UniformBlockScaleEntityStruct>(Id);
scaleStruct.scaleFactor = value;
Scale = new float3(value, value, value);
}
}
/// <summary>
/// The block's type (ID). Returns BlockIDs.Invalid if the block doesn't exist anymore.
/// </summary>
public BlockIDs Type
{
get
{
var id = (BlockIDs) BlockEngine.GetBlockInfo<DBEntityStruct>(Id, out var exists).DBID;
return exists ? id : BlockIDs.Invalid;
}
}
/// <summary>
/// The block's color. Returns BlockColors.Default if the block no longer exists.
/// </summary>
public BlockColor Color
{
get
{
byte index = BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(Id, out var exists).indexInPalette;
if (!exists) index = byte.MaxValue;
return new BlockColor(index);
}
set
{
ref var color = ref BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(Id);
color.indexInPalette = (byte)(value.Color + value.Darkness * 10);
color.overridePaletteColour = false;
color.needsUpdate = true;
BlockEngine.SetBlockColorFromPalette(ref color);
}
}
/// <summary>
/// The block's exact color. Gets reset to the palette color (Color property) after reentering the game.
/// </summary>
public float4 CustomColor
{
get => BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(Id).overriddenColour;
set
{
ref var color = ref BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(Id);
color.overriddenColour = value;
color.overridePaletteColour = true;
color.needsUpdate = true;
}
}
/// <summary>
/// The short text displayed on the block if applicable, or null.
/// Setting it is temporary to the session, it won't be saved.
/// </summary>
public string Label
{
get => BlockEngine.GetBlockInfo<TextLabelEntityViewStruct>(Id).textLabelComponent?.text;
set
{
ref var text = ref BlockEngine.GetBlockInfo<TextLabelEntityViewStruct>(Id);
if (text.textLabelComponent != null) text.textLabelComponent.text = value;
}
}
/// <summary>
/// Whether the block exists. The other properties will return a default value if the block doesn't exist.
/// </summary>
public bool Exists => BlockEngine.BlockExists(Id);
/// <summary>
/// Returns an array of blocks that are connected to this one. Returns an empty array if the block doesn't exist.
/// </summary>
public Block[] GetConnectedCubes() => BlockEngine.GetConnectedBlocks(Id);
/// <summary>
/// Removes this block.
/// </summary>
/// <returns>True if the block exists and could be removed.</returns>
public bool Remove() => RemovalEngine.RemoveBlock(Id);
/// <summary>
/// Returns the rigid body of the cluster of blocks this one belongs to during simulation.
/// Can be used to apply forces or move the block around while the simulation is running.
/// </summary>
/// <returns>The SimBody of the cluster or null if the block doesn't exist.</returns>
public SimBody GetSimBody()
{
uint id = BlockEngine.GetBlockInfo<GridConnectionsEntityStruct>(Id, out var exists).machineRigidBodyId;
return exists ? new SimBody(id) : null;
}
public override string ToString()
{
return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Type)}: {Type}, {nameof(Color)}: {Color}, {nameof(Exists)}: {Exists}";
}
public bool Equals(Block other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Id.Equals(other.Id);
}
public bool Equals(EGID other)
{
return Id.Equals(other);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Block) obj);
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
public static void Init()
{
GameEngineManager.AddGameEngine(PlacementEngine);
GameEngineManager.AddGameEngine(MovementEngine);
GameEngineManager.AddGameEngine(RotationEngine);
GameEngineManager.AddGameEngine(RemovalEngine);
GameEngineManager.AddGameEngine(BlockEngine);
GameEngineManager.AddGameEngine(BlockEventsEngine);
GameEngineManager.AddGameEngine(ScalingEngine);
}
/// <summary>
/// Convert the block to a specialised block class.
/// </summary>
/// <returns>The block.</returns>
/// <typeparam name="T">The specialised block type.</typeparam>
public T Specialise<T>() where T : Block
{
// What have I gotten myself into?
// C# can't cast to a child of Block unless the object was originally that child type
// And C# doesn't let me make implicit cast operators for child types
// So thanks to Microsoft, we've got this horrible implementation using reflection
ConstructorInfo ctor = typeof(T).GetConstructor(types: new System.Type[] { typeof(EGID) });
if (ctor == null)
{
throw new BlockSpecializationException("Specialized block constructor does not accept an EGID");
}
return (T)ctor.Invoke(new object[] { Id });
}
#if DEBUG
public static EntitiesDB entitiesDB
{
get
{
return BlockEngine.GetEntitiesDB();
}
}
#endif
internal static void Setup(World physicsWorld)
{
ScalingEngine.Setup(physicsWorld.EntityManager);
}
}
}

View file

@ -1,51 +0,0 @@
namespace GamecraftModdingAPI.Blocks
{
public struct BlockColor
{
public BlockColors Color;
public byte Darkness;
public BlockColor(byte index)
{
if (index == byte.MaxValue)
{
Color = BlockColors.Default;
Darkness = 0;
}
else
{
Color = (BlockColors) (index % 10);
Darkness = (byte) (index / 10);
}
}
public BlockColor(BlockColors color, byte darkness)
{
Color = color;
Darkness = darkness;
}
public override string ToString()
{
return $"{nameof(Color)}: {Color}, {nameof(Darkness)}: {Darkness}";
}
}
/// <summary>
/// Preset block colours
/// </summary>
public enum BlockColors
{
Default = byte.MaxValue,
White = 0,
Pink,
Purple,
Blue,
Aqua,
Green,
Lime,
Yellow,
Orange,
Red
}
}

View file

@ -1,204 +0,0 @@
using System.Collections.Generic;
using Gamecraft.Wires;
using RobocraftX.Blocks;
using RobocraftX.Common;
using RobocraftX.GUI.Hotbar.Colours;
using RobocraftX.Physics;
using RobocraftX.Scene.Simulation;
using Svelto.DataStructures;
using Svelto.ECS;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Engine for executing general block actions
/// </summary>
public class BlockEngine : IApiEngine
{
public string Name { get; } = "GamecraftModdingAPIBlockGameEngine";
public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => false;
internal bool Synced = true;
public void Dispose()
{
}
public void Ready()
{
}
public Block[] GetConnectedBlocks(EGID blockID)
{
if (!BlockExists(blockID)) return new Block[0];
Stack<EGID> cubeStack = new Stack<EGID>();
FasterList<EGID> cubes = new FasterList<EGID>(10);
var coll = entitiesDB.QueryEntities<GridConnectionsEntityStruct>();
foreach (var (ecoll, _) in coll)
foreach (ref var conn in ecoll)
conn.isProcessed = false;
ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubes,
(in GridConnectionsEntityStruct g) => { return false; });
var ret = new Block[cubes.count];
for (int i = 0; i < cubes.count; i++)
ret[i] = new Block(cubes[i]);
return ret;
}
public void SetBlockColorFromPalette(ref ColourParameterEntityStruct color)
{
ref var paletteEntry = ref entitiesDB.QueryEntity<PaletteEntryEntityStruct>(color.indexInPalette,
CommonExclusiveGroups.COLOUR_PALETTE_GROUP);
color.paletteColour = paletteEntry.Colour;
}
/// <summary>
/// Get a struct of a block. Can be used to set properties.
/// Returns a default value if not found.
/// </summary>
/// <param name="blockID">The block's ID</param>
/// <typeparam name="T">The struct to query</typeparam>
/// <returns>An editable reference to the struct</returns>
public ref T GetBlockInfo<T>(EGID blockID) where T : struct, IEntityComponent
{
if (!Synced)
{
Sync();
Synced = true;
}
if (entitiesDB.Exists<T>(blockID))
return ref entitiesDB.QueryEntity<T>(blockID);
T[] structHolder = new T[1]; //Create something that can be referenced
return ref structHolder[0]; //Gets a default value automatically
}
/// <summary>
/// Get a struct of a block. Can be used to set properties.
/// Returns a default value if not found.
/// </summary>
/// <param name="blockID">The block's ID</param>
/// <param name="exists">Whether the specified struct exists for the block</param>
/// <typeparam name="T">The struct to query</typeparam>
/// <returns>An editable reference to the struct</returns>
public ref T GetBlockInfo<T>(EGID blockID, out bool exists) where T : struct, IEntityComponent
{
if (!Synced)
{
Sync();
Synced = true;
}
exists = entitiesDB.Exists<T>(blockID);
if (exists)
return ref entitiesDB.QueryEntity<T>(blockID);
T[] structHolder = new T[1];
return ref structHolder[0];
}
public bool BlockExists(EGID id)
{
if (!Synced)
{
Sync();
Synced = true;
}
return entitiesDB.Exists<DBEntityStruct>(id);
}
public bool GetBlockInfoExists<T>(EGID blockID) where T : struct, IEntityComponent
{
if (!Synced)
{
Sync();
Synced = true;
}
return entitiesDB.Exists<T>(blockID);
}
public SimBody[] GetSimBodiesFromID(byte id)
{
var ret = new FasterList<SimBody>(4);
if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP))
return new SimBody[0];
var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP);
var connections = entitiesDB.QueryMappedEntities<GridConnectionsEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP);
foreach (ref ObjectIdEntityStruct oid in oids)
{
if (oid.objectId != id) continue;
var rid = connections.Entity(oid.ID.entityID).machineRigidBodyId;
foreach (var rb in ret)
{
if (rb.Id.entityID == rid)
goto DUPLICATE; //Multiple Object Identifiers on one rigid body
}
ret.Add(new SimBody(rid));
DUPLICATE: ;
}
return ret.ToArray();
}
public ObjectIdentifier[] GetObjectIDsFromID(byte id, bool sim)
{
var ret = new FasterList<ObjectIdentifier>(4);
if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP))
return new ObjectIdentifier[0];
var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP);
foreach (ref ObjectIdEntityStruct oid in oids)
if (sim ? oid.simObjectId == id : oid.objectId == id)
ret.Add(new ObjectIdentifier(oid.ID));
return ret.ToArray();
}
public SimBody[] GetConnectedSimBodies(uint id)
{
var joints = entitiesDB.QueryEntities<JointEntityStruct>(MachineSimulationGroups.JOINTS_GROUP);
var list = new FasterList<SimBody>(4);
foreach (var joint in joints)
{
if (joint.jointState == JointState.Broken) continue;
if (joint.connectedEntityA == id) list.Add(new SimBody(joint.connectedEntityB));
else if (joint.connectedEntityB == id) list.Add(new SimBody(joint.connectedEntityA));
}
return list.ToArray();
}
public EGID? FindBlockEGID(uint id)
{
var groups = entitiesDB.FindGroups<DBEntityStruct>();
foreach (ExclusiveGroupStruct group in groups)
{
if (entitiesDB.Exists<DBEntityStruct>(id, group))
return new EGID(id, group);
}
return null;
}
/// <summary>
/// Synchronize newly created entity components with entities DB.
/// This forces a partial game tick, so it may be slow.
/// This also has the potential to make Gamecraft unstable.
/// Use this sparingly.
/// </summary>
private static void Sync()
{
DeterministicStepCompositionRootPatch.SubmitEntitiesNow();
}
#if DEBUG
public EntitiesDB GetEntitiesDB()
{
return entitiesDB;
}
#endif
}
}

View file

@ -1,42 +0,0 @@
using System;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Utility;
using RobocraftX.Common;
using Svelto.ECS;
namespace GamecraftModdingAPI.Blocks
{
public class BlockEventsEngine : IReactionaryEngine<DBEntityStruct>
{
public event EventHandler<BlockPlacedRemovedEventArgs> Placed;
public event EventHandler<BlockPlacedRemovedEventArgs> Removed;
public void Ready()
{
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
}
public string Name { get; } = "GamecraftModdingAPIBlockEventsEngine";
public bool isRemovable { get; } = false;
public void Add(ref DBEntityStruct entityComponent, EGID egid)
{
ExceptionUtil.InvokeEvent(Placed, this, new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID});
}
public void Remove(ref DBEntityStruct entityComponent, EGID egid)
{
ExceptionUtil.InvokeEvent(Removed, this, new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID});
}
}
public struct BlockPlacedRemovedEventArgs
{
public EGID ID;
public BlockIDs Type;
}
}

View file

@ -1,270 +0,0 @@
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Possible block types
/// </summary>
public enum BlockIDs : ushort
{
/// <summary>
/// A custom value for the API. Doesn't exist for Gamecraft.
/// </summary>
Invalid = ushort.MaxValue,
AluminiumCube = 0,
AxleS,
HingeS = 3,
MotorS,
HingeM,
MotorM,
TyreM,
AxleM,
IronCube,
RubberCube,
OiledCube,
AluminiumConeSegment, //12
AluminiumCorner,
AluminiumRoundedCorner,
AluminiumSlicedCube,
AluminiumRoundedSlicedCube,
AluminiumCylinder,
AluminiumPyramidSegment,
AluminiumSlope,
AluminiumRoundedSlope,
AluminiumSphere,
RubberConeSegment, //22
RubberCorner,
RubberRoundedCorner,
RubberSlicedCube,
RubberRoundedSlicedCube,
RubberCylinder,
RubberPyramidSegment,
RubberSlope,
RubberRoundedSlope,
RubberSphere,
OiledConeSegment, //32
OiledCorner,
OiledRoundedCorner,
OiledSlicedCube,
OiledRoundedSlicedCube,
OiledCylinder,
OiledPyramidSegment,
OiledSlope,
OiledRoundedSlope,
OiledSphere,
IronConeSegment, //42
IronCorner,
IronRoundedCorner,
IronSlicedCube,
IronRoundedSlicedCube,
IronCylinder,
IronPyramidSegment,
IronSlope,
IronRoundedSlope,
IronSphere,
GlassCube, //52
GlassSlicedCube,
GlassSlope,
GlassCorner,
GlassPyramidSegment,
GlassRoundedSlicedCube,
GlassRoundedSlope,
GlassRoundedCorner,
GlassConeSegment,
GlassCylinder,
GlassSphere,
Lever, //63 - two IDs skipped
PlayerSpawn = 66, //Crashes without special handling
SmallSpawn,
MediumSpawn,
LargeSpawn,
BallJoint,
UniversalJoint,
ServoAxle,
ServoHinge,
StepperAxle,
StepperHinge,
TelescopicJoint,
DampedSpring,
ServoPiston,
StepperPiston,
PneumaticPiston,
PneumaticHinge,
PneumaticAxle, //82
PilotSeat = 90, //Might crash
PassengerSeat,
PilotControls,
GrassCube,
DirtCube,
GrassConeSegment,
GrassCorner,
GrassRoundedCorner,
GrassSlicedCube,
GrassRoundedSlicedCube,
GrassPyramidSegment,
GrassSlope,
GrassRoundedSlope,
DirtConeSegment,
DirtCorner,
DirtRoundedCorner,
DirtSlicedCube,
DirtRoundedSlicedCube,
DirtPyramidSegment,
DirtSlope,
DirtRoundedSlope,
RubberHemisphere,
AluminiumHemisphere,
GrassInnerCornerBulged,
DirtInnerCornerBulged,
IronHemisphere,
OiledHemisphere,
GlassHemisphere,
TyreS,
ThreeWaySwitch,
Dial, //120
CharacterOnEnterTrigger, //Probably crashes
CharacterOnLeaveTrigger,
CharacterOnStayTrigger,
ObjectOnEnterTrigger,
ObjectOnLeaveTrigger,
ObjectOnStayTrigger,
Button,
Switch,
TextBlock, //Brings up a screen
ConsoleBlock, //Brings up a screen
Door,
GlassDoor,
PoweredDoor,
PoweredGlassDoor,
AluminiumTubeCorner,
IronTubeCorner,
WoodCube,
WoodSlicedCube,
WoodSlope,
WoodCorner,
WoodPyramidSegment,
WoodConeSegment,
WoodRoundedSlicedCube,
WoodRoundedSlope,
WoodRoundedCorner,
WoodCylinder,
WoodHemisphere,
WoodSphere,
BrickCube, //149
BrickSlicedCube = 151,
BrickSlope,
BrickCorner,
ConcreteCube,
ConcreteSlicedCube,
ConcreteSlope,
ConcreteCorner,
RoadCarTyre,
OffRoadCarTyre,
RacingCarTyre,
BicycleTyre,
FrontBikeTyre,
RearBikeTyre,
ChopperBikeTyre,
TractorTyre,
MonsterTruckTyre,
MotocrossBikeTyre,
CartTyre, //168
ObjectIdentifier,
ANDLogicBlock,
NANDLogicBlock,
NORLogicBlock,
NOTLogicBlock,
ORLogicBlock,
XNORLogicBlock,
XORLogicBlock,
AbsoluteMathsBlock,
AdderMathsBlock,
DividerMathsBlock,
SignMathsBlock, //180
MaxMathsBlock,
MinMathsBlock,
MultiplierMathsBlock,
SubtractorMathsBlock,
SimpleConnector,
MeanMathsBlock,
Bit,
Counter,
Timer,
ObjectFilter,
PlayerFilter,
TeamFilter,
Number2Text, //193
BeachTree1 = 200,
BeachTree2,
BeachTree3,
Rock1,
Rock2,
Rock3,
Rock4,
BirchTree1,
BirchTree2,
BirchTree3,
PineTree1,
PineTree2,
PineTree3,
Flower1,
Flower2,
Flower3,
Shrub1,
Shrub2,
Shrub3,
CliffCube,
CliffSlicedCorner,
CliffCornerA,
CliffCornerB,
CliffSlopeA,
CliffSlopeB,
GrassEdge,
GrassEdgeInnerCorner,
GrassEdgeCorner,
GrassEdgeSlope,
CentreHUD,
ObjectiveHUD,
GameStatsHUD, //231
GameOverBlock,
SFXBlockGameplay=240,
SFXBlock8Bit,
SFXBlockInstrument,
SFXBlockSciFi,
SFXBlockLoops,
SFXBlockVocal,
MovementConstrainer, //246
RotationConstrainer,
AdvancedMovementDampener,
AdvancedRotationDampener,
Mover = 250,
Rotator,
MovementDampener,
RotationDampener,
AdvancedMover,
AdvancedRotator,
MusicBlock, //256
PlasmaCannonBlock,
MagmaRockCube=777,
MagmaRockCubeSliced,
MagmaRockSlope,
MagmaRockCorner,
MagmaRockPyramidSegment,
MagmaRockConeSegment,
MagmaRockSlicedRounded,
MagmaRockSlopeRounded,
MagmaRockCornerRounded,
HexNetCube,
HexNetCubeSliced,
HexNetSlope,
HexNetCorner,
HexNetPyramidSegment,
HexNetConeSegment,
HexNetSlicedRounded,
HexNetSlopeRounded,
HexNetCornerRounded, //794
MagmaRockBulgedInner,
HexNetCylinder=797,
HexNetHemisphere,
HexNetSphere,
HexNetTubeCorner //800
}
}

View file

@ -1,42 +0,0 @@
using Svelto.ECS;
using RobocraftX.Common;
using HarmonyLib;
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// ExclusiveGroups and IDs used with blocks
/// </summary>
public static class BlockIdentifiers
{
/// <summary>
/// Blocks placed by the player
/// </summary> - TODO
//public static ExclusiveGroup OWNED_BLOCKS { get { return CommonExclusiveGroups.REAL_BLOCKS_GROUPS_DON_T_USE_IN_NEW_CODE; } }
/// <summary>
/// Extra parts used in functional blocks
/// </summary>
public static ExclusiveGroup FUNCTIONAL_BLOCK_PARTS { get { return CommonExclusiveGroups.FUNCTIONAL_BLOCK_PART_GROUP; } }
/// <summary>
/// Blocks which are disabled in Simulation mode
/// </summary>
public static ExclusiveGroup SIM_BLOCKS_DISABLED { get { return CommonExclusiveGroups.DISABLED_JOINTS_IN_SIM_GROUP; } }
//public static ExclusiveGroup SPAWN_POINTS { get { return CommonExclusiveGroups.SPAWN_POINTS_GROUP; } }
//public static ExclusiveGroup SPAWN_POINTS_DISABLED { get { return CommonExclusiveGroups.SPAWN_POINTS_DISABLED_GROUP; } }
/// <summary>
/// The ID of the most recently placed block
/// </summary>
public static uint LatestBlockID {
get
{ //Need the private field as the property increments itself
return ((uint) AccessTools.Field(typeof(CommonExclusiveGroups), "_nextBlockEntityID").GetValue(null)) - 1;
}
}
}
}

View file

@ -1,77 +0,0 @@
using System;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Tests;
namespace GamecraftModdingAPI.Blocks
{
#if TEST
/// <summary>
/// Block test cases. Not accessible in release versions.
/// </summary>
[APITestClass]
public static class BlockTests
{
[APITestCase(TestType.EditMode)]
public static void TestPlaceNew()
{
Block newBlock = Block.PlaceNew(BlockIDs.AluminiumCube, Unity.Mathematics.float3.zero);
Assert.NotNull(newBlock.Id, "Newly placed block is missing Id. This should be populated when the block is placed.", "Newly placed block Id is not null, block successfully placed.");
}
[APITestCase(TestType.EditMode)]
public static void TestSync()
{
Block newBlock = Block.PlaceNew(BlockIDs.AluminiumCube, Unity.Mathematics.float3.zero + 2);
if (!Assert.CloseTo(newBlock.Position, (Unity.Mathematics.float3.zero + 2), $"Newly placed block at {newBlock.Position} is expected at {Unity.Mathematics.float3.zero + 2}.", "Newly placed block position matches.")) return;
Assert.Equal(newBlock.Exists, true, "Newly placed block does not exist, possibly because Sync() skipped/missed/failed.", "Newly placed block exists, Sync() successful.");
}
[APITestCase(TestType.EditMode)]
public static void TestTextBlock()
{
Block newBlock = Block.PlaceNew(BlockIDs.TextBlock, Unity.Mathematics.float3.zero + 1);
TextBlock textBlock = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler
Assert.Errorless(() => { textBlock = newBlock.Specialise<TextBlock>(); }, "Block.Specialize<TextBlock>() raised an exception: ", "Block.Specialize<TextBlock>() completed without issue.");
if (!Assert.NotNull(textBlock, "Block.Specialize<TextBlock>() returned null, possibly because it failed silently.", "Specialized TextBlock is not null.")) return;
if (!Assert.NotNull(textBlock.Text, "TextBlock.Text is null, possibly because it failed silently.", "TextBlock.Text is not null.")) return;
if (!Assert.NotNull(textBlock.TextBlockId, "TextBlock.TextBlockId is null, possibly because it failed silently.", "TextBlock.TextBlockId is not null.")) return;
}
[APITestCase(TestType.EditMode)]
public static void TestMotor()
{
Block newBlock = Block.PlaceNew(BlockIDs.MotorS, Unity.Mathematics.float3.zero + 1);
Motor b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler
Assert.Errorless(() => { b = newBlock.Specialise<Motor>(); }, "Block.Specialize<Motor>() raised an exception: ", "Block.Specialize<Motor>() completed without issue.");
if (!Assert.NotNull(b, "Block.Specialize<Motor>() returned null, possibly because it failed silently.", "Specialized Motor is not null.")) return;
if (!Assert.CloseTo(b.Torque, 75f, $"Motor.Torque {b.Torque} does not equal default value, possibly because it failed silently.", "Motor.Torque close enough to default.")) return;
if (!Assert.CloseTo(b.TopSpeed, 30f, $"Motor.TopSpeed {b.TopSpeed} does not equal default value, possibly because it failed silently.", "Motor.Torque is close enough to default.")) return;
if (!Assert.Equal(b.Reverse, false, $"Motor.Reverse {b.Reverse} does not equal default value, possibly because it failed silently.", "Motor.Reverse is default.")) return;
}
[APITestCase(TestType.EditMode)]
public static void TestPiston()
{
Block newBlock = Block.PlaceNew(BlockIDs.PneumaticPiston, Unity.Mathematics.float3.zero + 1);
Piston b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler
Assert.Errorless(() => { b = newBlock.Specialise<Piston>(); }, "Block.Specialize<Piston>() raised an exception: ", "Block.Specialize<Piston>() completed without issue.");
if (!Assert.NotNull(b, "Block.Specialize<Piston>() returned null, possibly because it failed silently.", "Specialized Piston is not null.")) return;
if (!Assert.CloseTo(b.MaximumExtension, 1.01f, $"Piston.MaximumExtension {b.MaximumExtension} does not equal default value, possibly because it failed silently.", "Piston.MaximumExtension is close enough to default.")) return;
if (!Assert.CloseTo(b.MaximumForce, 750f, $"Piston.MaximumForce {b.MaximumForce} does not equal default value, possibly because it failed silently.", "Piston.MaximumForce is close enough to default.")) return;
}
[APITestCase(TestType.EditMode)]
public static void TestServo()
{
Block newBlock = Block.PlaceNew(BlockIDs.ServoAxle, Unity.Mathematics.float3.zero + 1);
Servo b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler
Assert.Errorless(() => { b = newBlock.Specialise<Servo>(); }, "Block.Specialize<Servo>() raised an exception: ", "Block.Specialize<Servo>() completed without issue.");
if (!Assert.NotNull(b, "Block.Specialize<Servo>() returned null, possibly because it failed silently.", "Specialized Servo is not null.")) return;
if (!Assert.CloseTo(b.MaximumAngle, 180f, $"Servo.MaximumAngle {b.MaximumAngle} does not equal default value, possibly because it failed silently.", "Servo.MaximumAngle is close enough to default.")) return;
if (!Assert.CloseTo(b.MinimumAngle, -180f, $"Servo.MinimumAngle {b.MinimumAngle} does not equal default value, possibly because it failed silently.", "Servo.MinimumAngle is close enough to default.")) return;
if (!Assert.CloseTo(b.MaximumForce, 750f, $"Servo.MaximumForce {b.MaximumForce} does not equal default value, possibly because it failed silently.", "Servo.MaximumForce is close enough to default.")) return;
}
}
#endif
}

View file

@ -1,90 +0,0 @@
using System;
using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class ConsoleBlock : Block
{
public static ConsoleBlock PlaceNew(float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
EGID id = PlacementEngine.PlaceBlock(BlockIDs.ConsoleBlock, color, darkness,
position, uscale, scale, player, rotation);
return new ConsoleBlock(id);
}
return null;
}
public ConsoleBlock(EGID id): base(id)
{
if (!BlockEngine.GetBlockInfoExists<ConsoleBlockEntityStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
public ConsoleBlock(uint id): base(new EGID(id, CommonExclusiveGroups.BUILD_CONSOLE_BLOCK_GROUP))
{
if (!BlockEngine.GetBlockInfoExists<ConsoleBlockEntityStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
// custom console block properties
public string Command
{
get
{
return BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).commandName;
}
set
{
BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).commandName.Set(value);
}
}
public string Arg1
{
get => BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg1;
set
{
BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg1.Set(value);
}
}
public string Arg2
{
get => BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg2;
set
{
BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg2.Set(value);
}
}
public string Arg3
{
get => BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg3;
set
{
BlockEngine.GetBlockInfo<ConsoleBlockEntityStruct>(Id).arg3.Set(value);
}
}
}
}

View file

@ -1,106 +0,0 @@
using System;
using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class Motor : Block
{
/// <summary>
/// Places a new motor.
/// Any valid motor type is accepted.
/// This re-implements Block.PlaceNew(...)
/// </summary>
public static new Motor PlaceNew(BlockIDs block, float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (!(block == BlockIDs.MotorS || block == BlockIDs.MotorM))
{
throw new BlockTypeException($"Block is not a {typeof(Motor).Name} block");
}
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
position, uscale, scale, player, rotation);
return new Motor(id);
}
return null;
}
public Motor(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
public Motor(uint id): base(new EGID(id, CommonExclusiveGroups.BUILD_MOTOR_BLOCK_GROUP))
{
if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
// custom motor properties
/// <summary>
/// The motor's maximum rotational velocity.
/// </summary>
public float TopSpeed
{
get
{
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxVelocity;
}
set
{
ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
motor.maxVelocity = value;
}
}
/// <summary>
/// The motor's maximum rotational force.
/// </summary>
public float Torque
{
get
{
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxForce;
}
set
{
ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
motor.maxForce = value;
}
}
/// <summary>
/// The motor's direction.
/// </summary>
public bool Reverse
{
get
{
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).reverse;
}
set
{
ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
motor.reverse = value;
}
}
}
}

View file

@ -1,57 +0,0 @@
using Gamecraft.Wires;
using RobocraftX.Common;
using Svelto.ECS;
namespace GamecraftModdingAPI.Blocks
{
public class ObjectIdentifier : Block
{
public ObjectIdentifier(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists<ObjectIdEntityStruct>(Id))
{
throw new BlockTypeException($"Block is not a {GetType().Name} block");
}
}
public ObjectIdentifier(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP))
{
if (!BlockEngine.GetBlockInfoExists<ObjectIdEntityStruct>(Id))
{
throw new BlockTypeException($"Block is not a {GetType().Name} block");
}
}
public char Identifier
{
get => (char) (BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(Id).objectId + 'A');
set
{
BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(Id).objectId = (byte) (value - 'A');
Label = value + ""; //The label isn't updated automatically
}
}
/// <summary>
/// Simulation-time ID. Assigned by the game starting from 0.
/// </summary>
public byte SimID
{
get => BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(Id).simObjectId;
}
/// <summary>
/// Finds the identifier blocks with the given ID.
/// </summary>
/// <param name="id">The ID to look for</param>
/// <returns>An array that may be empty</returns>
public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A'), false);
/// <summary>
/// Finds the identifier blocks with the given simulation-time ID. This ID is assigned by the game starting from 0.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static ObjectIdentifier[] GetBySimID(byte id) => BlockEngine.GetObjectIDsFromID(id, true);
}
}

View file

@ -1,83 +0,0 @@
using System;
using RobocraftX.Blocks;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI.Utility;
using RobocraftX.Common;
namespace GamecraftModdingAPI.Blocks
{
public class Piston : Block
{
/// <summary>
/// Places a new piston.
/// Any valid piston type is accepted.
/// This re-implements Block.PlaceNew(...)
/// </summary>
public static new Piston PlaceNew(BlockIDs block, float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (!(block == BlockIDs.ServoPiston || block == BlockIDs.StepperPiston || block == BlockIDs.PneumaticPiston))
{
throw new BlockTypeException($"Block is not a {typeof(Piston).Name} block");
}
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
position, uscale, scale, player, rotation);
return new Piston(id);
}
return null;
}
public Piston(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists<PistonReadOnlyStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
public Piston(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_PISTON_BLOCK_GROUP))
{
if (!BlockEngine.GetBlockInfoExists<PistonReadOnlyStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
// custom piston properties
/// <summary>
/// The piston's max extension distance.
/// </summary>
public float MaximumExtension
{
get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id).maxDeviation;
set
{
ref PistonReadOnlyStruct piston = ref BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id);
piston.maxDeviation = value;
}
}
/// <summary>
/// The piston's max extension force.
/// </summary>
public float MaximumForce
{
get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id).maxForce;
set
{
ref PistonReadOnlyStruct piston = ref BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(Id);
piston.maxForce = value;
}
}
}
}

View file

@ -1,132 +0,0 @@
using System;
using System.Reflection;
using DataLoader;
using HarmonyLib;
using RobocraftX.Blocks;
using RobocraftX.Blocks.Scaling;
using RobocraftX.Character;
using RobocraftX.Common;
using RobocraftX.CR.MachineEditing;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Mathematics;
using UnityEngine;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Players;
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Engine which executes block placement actions
/// </summary>
public class PlacementEngine : IApiEngine
{
public bool IsInGame;
public void Dispose()
{
IsInGame = false;
}
public void Ready()
{
IsInGame = true;
}
public EntitiesDB entitiesDB { get; set; }
private static BlockEntityFactory _blockEntityFactory; //Injected from PlaceBlockEngine
public EGID PlaceBlock(BlockIDs block, BlockColors color, byte darkness, float3 position, int uscale,
float3 scale, Player player, float3 rotation)
{ //It appears that only the non-uniform scale has any visible effect, but if that's not given here it will be set to the uniform one
if (darkness > 9)
throw new Exception("That is too dark. Make sure to use 0-9 as darkness. (0 is default.)");
return BuildBlock((ushort) block, (byte) (color + darkness * 10), position, uscale, scale, rotation,
(player ?? new Player(PlayerType.Local)).Id);
}
private EGID BuildBlock(ushort block, byte color, float3 position, int uscale, float3 scale, float3 rot, uint playerId)
{
if (_blockEntityFactory == null)
throw new Exception("The factory is null.");
if (uscale < 1)
throw new Exception("Scale needs to be at least 1");
if (scale.x < 4e-5) scale.x = uscale;
if (scale.y < 4e-5) scale.y = uscale;
if (scale.z < 4e-5) scale.z = uscale;
uint dbid = block;
if (!PrefabsID.DBIDMAP.ContainsKey(dbid))
throw new Exception("Block with ID " + dbid + " not found!");
//RobocraftX.CR.MachineEditing.PlaceBlockEngine
ScalingEntityStruct scaling = new ScalingEntityStruct {scale = scale};
Quaternion rotQ = Quaternion.Euler(rot);
RotationEntityStruct rotation = new RotationEntityStruct {rotation = rotQ};
GridRotationStruct gridRotation = new GridRotationStruct
{position = position, rotation = rotQ};
DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid};
BlockPlacementScaleEntityStruct placementScale = new BlockPlacementScaleEntityStruct
{
blockPlacementHeight = uscale, blockPlacementWidth = uscale, desiredScaleFactor = uscale,
snapGridScale = uscale,
unitSnapOffset = 0, isUsingUnitSize = true
};
EquippedColourStruct colour = new EquippedColourStruct {indexInPalette = color};
EntityComponentInitializer
structInitializer =
_blockEntityFactory.Build(CommonExclusiveGroups.nextBlockEntityID, dbid); //The ghost block index is only used for triggers
if (colour.indexInPalette != byte.MaxValue)
structInitializer.Init(new ColourParameterEntityStruct
{
indexInPalette = colour.indexInPalette,
needsUpdate = true
});
uint prefabId = PrefabsID.GetPrefabId(dbid, 0);
structInitializer.Init(new GFXPrefabEntityStructGPUI(prefabId));
structInitializer.Init(new PhysicsPrefabEntityStruct(prefabId));
structInitializer.Init(dbEntity);
structInitializer.Init(new PositionEntityStruct {position = position});
structInitializer.Init(rotation);
structInitializer.Init(scaling);
structInitializer.Init(gridRotation);
structInitializer.Init(new UniformBlockScaleEntityStruct
{
scaleFactor = placementScale.desiredScaleFactor
});
structInitializer.Init(new BlockPlacementInfoStruct()
{
loadedFromDisk = false,
placedBy = playerId
});
PrimaryRotationUtility.InitialisePrimaryDirection(rotation.rotation, ref structInitializer);
EGID playerEGID = new EGID(playerId, CharacterExclusiveGroups.OnFootGroup);
ref PickedBlockExtraDataStruct pickedBlock = ref entitiesDB.QueryEntity<PickedBlockExtraDataStruct>(playerEGID);
pickedBlock.placedBlockEntityID = structInitializer.EGID;
pickedBlock.placedBlockWasAPickedBlock = false;
Block.BlockEngine.Synced = false; // Block entities will need to be submitted before properties can be used
return structInitializer.EGID;
}
public string Name { get; } = "GamecraftModdingAPIPlacementGameEngine";
public bool isRemovable => false;
[HarmonyPatch]
public class FactoryObtainerPatch
{
static void Postfix(BlockEntityFactory blockEntityFactory)
{
_blockEntityFactory = blockEntityFactory;
Logging.MetaDebugLog("Block entity factory injected.");
}
static MethodBase TargetMethod(Harmony instance)
{
return AccessTools.TypeByName("RobocraftX.CR.MachineEditing.PlaceBlockEngine").GetConstructors()[0];
}
}
}
}

View file

@ -1,72 +0,0 @@
using RobocraftX.Common;
using RobocraftX.UECS;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Mathematics;
using UnityEngine;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Engine which executes block movement actions
/// </summary>
public class RotationEngine : IApiEngine
{
public string Name { get; } = "GamecraftModdingAPIRotationGameEngine";
public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => false;
public bool IsInGame = false;
public void Dispose()
{
IsInGame = false;
}
public void Ready()
{
IsInGame = true;
}
// implementations for Rotation static class
public float3 RotateBlock(EGID blockID, Vector3 vector)
{
ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID);
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID);
ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID);
// main (persistent) position
Quaternion newRotation = (Quaternion)rotStruct.rotation;
newRotation.eulerAngles += vector;
rotStruct.rotation = (quaternion)newRotation;
// placement grid rotation
Quaternion newGridRotation = (Quaternion)gridStruct.rotation;
newGridRotation.eulerAngles += vector;
gridStruct.rotation = (quaternion)newGridRotation;
// rendered position
Quaternion newTransRotation = (Quaternion)rotStruct.rotation;
newTransRotation.eulerAngles += vector;
transStruct.rotation = newTransRotation;
// collision position
FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Unity.Transforms.Rotation
{
Value = rotStruct.rotation
});
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID).isProcessed = false;
return ((Quaternion)rotStruct.rotation).eulerAngles;
}
public float3 GetRotation(EGID blockID)
{
ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
return ((Quaternion) rotStruct.rotation).eulerAngles;
}
}
}

View file

@ -1,111 +0,0 @@
using System;
using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class Servo : Block
{
/// <summary>
/// Places a new servo.
/// Any valid servo type is accepted.
/// This re-implements Block.PlaceNew(...)
/// </summary>
public static new Servo PlaceNew(BlockIDs block, float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (!(block == BlockIDs.ServoAxle || block == BlockIDs.ServoHinge || block == BlockIDs.ServoPiston))
{
throw new BlockTypeException($"Block is not a {nameof(Servo)} block");
}
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
position, uscale, scale, player, rotation);
return new Servo(id);
}
return null;
}
public Servo(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
public Servo(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SERVO_BLOCK_GROUP))
{
if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
// custom servo properties
/// <summary>
/// The servo's minimum angle.
/// </summary>
public float MinimumAngle
{
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).minDeviation;
set
{
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
servo.minDeviation = value;
}
}
/// <summary>
/// The servo's maximum angle.
/// </summary>
public float MaximumAngle
{
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxDeviation;
set
{
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
servo.maxDeviation = value;
}
}
/// <summary>
/// The servo's maximum force.
/// </summary>
public float MaximumForce
{
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxForce;
set
{
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
servo.maxForce = value;
}
}
/// <summary>
/// The servo's direction.
/// </summary>
public bool Reverse
{
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).reverse;
set
{
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
servo.reverse = value;
}
}
}
}

View file

@ -1,195 +0,0 @@
using Svelto.ECS;
using Svelto.DataStructures;
using Gamecraft.Wires;
using GamecraftModdingAPI.Engines;
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Engine which executes signal actions
/// </summary>
public class SignalEngine : IApiEngine
{
public const float POSITIVE_HIGH = 1.0f;
public const float NEGATIVE_HIGH = -1.0f;
public const float HIGH = 1.0f;
public const float ZERO = 0.0f;
public string Name { get; } = "GamecraftModdingAPISignalGameEngine";
public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => false;
public bool IsInGame = false;
public void Dispose()
{
IsInGame = false;
}
public void Ready()
{
IsInGame = true;
}
// implementations for Signal static class
public bool SetSignal(EGID blockID, float signal, out uint signalID, bool input = true)
{
signalID = GetSignalIDs(blockID, input)[0];
return SetSignal(signalID, signal);
}
public bool SetSignal(uint signalID, float signal, bool input = true)
{
var array = GetSignalStruct(signalID, out uint index, input);
if (array.count > 0) array[index].valueAsFloat = signal;
return false;
}
public float AddSignal(EGID blockID, float signal, out uint signalID, bool clamp = true, bool input = true)
{
signalID = GetSignalIDs(blockID, input)[0];
return AddSignal(signalID, signal, clamp, input);
}
public float AddSignal(uint signalID, float signal, bool clamp = true, bool input = true)
{
var array = GetSignalStruct(signalID, out uint index, input);
if (array.count > 0)
{
ref var channelData = ref array[index];
channelData.valueAsFloat += signal;
if (clamp)
{
if (channelData.valueAsFloat > POSITIVE_HIGH)
{
channelData.valueAsFloat = POSITIVE_HIGH;
}
else if (channelData.valueAsFloat < NEGATIVE_HIGH)
{
channelData.valueAsFloat = NEGATIVE_HIGH;
}
return channelData.valueAsFloat;
}
}
return signal;
}
public float GetSignal(EGID blockID, out uint signalID, bool input = true)
{
signalID = GetSignalIDs(blockID, input)[0];
return GetSignal(signalID, input);
}
public float GetSignal(uint signalID, bool input = true)
{
var array = GetSignalStruct(signalID, out uint index, input);
return array.count > 0 ? array[index].valueAsFloat : 0f;
}
public uint[] GetSignalIDs(EGID blockID, bool input = true)
{
ref BlockPortsStruct bps = ref entitiesDB.QueryEntity<BlockPortsStruct>(blockID);
uint[] signals;
if (input) {
signals = new uint[bps.inputCount];
for (uint i = 0u; i < bps.inputCount; i++)
{
signals[i] = bps.firstInputID + i;
}
} else {
signals = new uint[bps.outputCount];
for (uint i = 0u; i < bps.outputCount; i++)
{
signals[i] = bps.firstOutputID + i;
}
}
return signals;
}
public EGID[] GetSignalInputs(EGID blockID)
{
BlockPortsStruct ports = entitiesDB.QueryEntity<BlockPortsStruct>(blockID);
EGID[] inputs = new EGID[ports.inputCount];
for (uint i = 0; i < ports.inputCount; i++)
{
inputs[i] = new EGID(i + ports.firstInputID, NamedExclusiveGroup<InputPortsGroup>.Group);
}
return inputs;
}
public EGID[] GetSignalOutputs(EGID blockID)
{
BlockPortsStruct ports = entitiesDB.QueryEntity<BlockPortsStruct>(blockID);
EGID[] outputs = new EGID[ports.outputCount];
for (uint i = 0; i < ports.outputCount; i++)
{
outputs[i] = new EGID(i + ports.firstOutputID, NamedExclusiveGroup<OutputPortsGroup>.Group);
}
return outputs;
}
public ref WireEntityStruct MatchPortToWire(EGID portID, EGID blockID, out bool exists)
{
ref PortEntityStruct port = ref entitiesDB.QueryEntity<PortEntityStruct>(portID);
var wires = entitiesDB.QueryEntities<WireEntityStruct>(NamedExclusiveGroup<WiresGroup>.Group);
for (uint i = 0; i < wires.count; i++)
{
if ((wires[i].destinationPortUsage == port.usage && wires[i].destinationBlockEGID == blockID)
|| (wires[i].sourcePortUsage == port.usage && wires[i].sourceBlockEGID == blockID))
{
exists = true;
return ref wires[i];
}
}
exists = false;
WireEntityStruct[] defRef = new WireEntityStruct[1];
return ref defRef[0];
}
public ref ChannelDataStruct GetChannelDataStruct(EGID portID, out bool exists)
{
ref PortEntityStruct port = ref entitiesDB.QueryEntity<PortEntityStruct>(portID);
var channels = entitiesDB.QueryEntities<ChannelDataStruct>(NamedExclusiveGroup<ChannelDataGroup>.Group);
if (port.firstChannelIndexCachedInSim < channels.count)
{
exists = true;
return ref channels[port.firstChannelIndexCachedInSim];
}
exists = false;
ChannelDataStruct[] defRef = new ChannelDataStruct[1];
return ref defRef[0];
}
public EGID[] GetElectricBlocks()
{
var res = new FasterList<EGID>();
foreach (var (coll, _) in entitiesDB.QueryEntities<BlockPortsStruct>())
foreach (ref BlockPortsStruct s in coll)
res.Add(s.ID);
return res.ToArray();
}
private EntityCollection<ChannelDataStruct> GetSignalStruct(uint signalID, out uint index, bool input = true)
{
ExclusiveGroup group = input
? NamedExclusiveGroup<InputPortsGroup>.Group
: NamedExclusiveGroup<OutputPortsGroup>.Group;
if (entitiesDB.Exists<PortEntityStruct>(signalID, group))
{
index = entitiesDB.QueryEntity<PortEntityStruct>(signalID, group).anyChannelIndex;
var channelData =
entitiesDB.QueryEntities<ChannelDataStruct>(NamedExclusiveGroup<ChannelDataGroup>.Group);
return channelData;
}
index = 0;
return default; //count: 0
}
}
}

View file

@ -1,123 +0,0 @@
using System;
using Gamecraft.Wires;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// Common implementation for blocks that support wiring.
/// </summary>
public class SignalingBlock : Block
{
/// <summary>
/// Places a new signaling block.
/// Any valid functional block type with IO ports will work.
/// This re-implements Block.PlaceNew(...)
/// </summary>
public static new SignalingBlock PlaceNew(BlockIDs block, float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
position, uscale, scale, player, rotation);
return new SignalingBlock(id);
}
return null;
}
public SignalingBlock(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists<BlockPortsStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
public SignalingBlock(uint id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists<BlockPortsStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
protected ref BlockPortsStruct GetBlockPortsStruct()
{
return ref BlockEngine.GetBlockInfo<BlockPortsStruct>(Id);
}
/// <summary>
/// Generates the input port identifiers.
/// </summary>
/// <returns>The input identifiers.</returns>
protected EGID[] GetInputIds()
{
return SignalEngine.GetSignalInputs(Id);
}
/// <summary>
/// Generates the output port identifiers.
/// </summary>
/// <returns>The output identifiers.</returns>
protected EGID[] GetOutputIds()
{
return SignalEngine.GetSignalOutputs(Id);
}
/// <summary>
/// Gets the port struct.
/// </summary>
/// <returns>The port struct.</returns>
/// <param name="portId">Port identifier.</param>
protected ref PortEntityStruct GetPortStruct(EGID portId)
{
return ref BlockEngine.GetBlockInfo<PortEntityStruct>(portId);
}
/// <summary>
/// Gets the connected wire.
/// </summary>
/// <returns>The connected wire.</returns>
/// <param name="portId">Port identifier.</param>
/// <param name="connected">Whether the port has a wire connected to it.</param>
protected ref WireEntityStruct GetConnectedWire(EGID portId, out bool connected)
{
return ref SignalEngine.MatchPortToWire(portId, Id, out connected);
}
/// <summary>
/// [EXPERIMENTAL] Gets the channel data.
/// </summary>
/// <returns>The channel data.</returns>
/// <param name="portId">Port identifier.</param>
/// <param name="exists">Whether the channel actually exists.</param>
protected ref ChannelDataStruct GetChannelData(EGID portId, out bool exists)
{
return ref SignalEngine.GetChannelDataStruct(portId, out exists);
}
/// <summary>
/// The input port count.
/// </summary>
public uint InputCount
{
get => GetBlockPortsStruct().inputCount;
}
/// <summary>
/// The output port count.
/// </summary>
public uint OutputCount
{
get => GetBlockPortsStruct().outputCount;
}
}
}

View file

@ -1,125 +0,0 @@
using System;
using RobocraftX.Blocks;
using RobocraftX.Common;
using Gamecraft.CharacterVulnerability;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class SpawnPoint : Block
{
/// <summary>
/// Places a new spawn point.
/// Any valid spawn block type is accepted.
/// This re-implements Block.PlaceNew(...)
/// </summary>
public static new SpawnPoint PlaceNew(BlockIDs block, float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (!(block == BlockIDs.LargeSpawn || block == BlockIDs.SmallSpawn || block == BlockIDs.MediumSpawn || block == BlockIDs.PlayerSpawn))
{
throw new BlockTypeException($"Block is not a {nameof(SpawnPoint)} block");
}
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
position, uscale, scale, player, rotation);
return new SpawnPoint(id);
}
return null;
}
public SpawnPoint(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists<SpawnPointStatsEntityStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
public SpawnPoint(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SPAWNPOINT_BLOCK_GROUP))
{
if (!BlockEngine.GetBlockInfoExists<SpawnPointStatsEntityStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
// custom spawn point properties
/// <summary>
/// The lives the player spawns in with.
/// </summary>
public uint Lives
{
get
{
return BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id).lives;
}
set
{
ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id);
spses.lives = value;
}
}
/// <summary>
/// Whether the spawned player can take damage.
/// </summary>
public bool Damageable
{
get
{
return BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id).canTakeDamage;
}
set
{
ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id);
spses.canTakeDamage = value;
}
}
/// <summary>
/// Whether the game over screen will be displayed
/// </summary>
public bool GameOverEnabled
{
get
{
return BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id).gameOverScreen;
}
set
{
ref SpawnPointStatsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(Id);
spses.gameOverScreen = value;
}
}
/// <summary>
/// The team id for players who spawn here.
/// </summary>
public byte Team
{
get
{
return BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(Id).teamId;
}
set
{
ref SpawnPointIdsEntityStruct spses = ref BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(Id);
spses.teamId = value;
}
}
}
}

View file

@ -1,84 +0,0 @@
using System;
using Gamecraft.Blocks.GUI;
using RobocraftX.Common;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class TextBlock : Block
{
public static TextBlock PlaceNew(float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
EGID id = PlacementEngine.PlaceBlock(BlockIDs.TextBlock, color, darkness,
position, uscale, scale, player, rotation);
return new TextBlock(id);
}
return null;
}
public TextBlock(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
public TextBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TEXT_BLOCK_GROUP))
{
if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
// custom text block properties
/// <summary>
/// The text block's current text.
/// </summary>
public string Text
{
get
{
return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textCurrent;
}
set
{
ref TextBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id);
tbds.textCurrent.Set(value);
tbds.textStored.Set(value);
BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockStringContent.Set(value);
}
}
/// <summary>
/// The text block's current text block ID (used in ChangeTextBlockCommand).
/// </summary>
public string TextBlockId
{
get
{
return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID;
}
set
{
BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID.Set(value);
BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockID.Set(value);
}
}
}
}

View file

@ -1,119 +0,0 @@
using System;
using RobocraftX.Blocks;
using RobocraftX.Common;
using Gamecraft.Blocks.TimerBlock;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class Timer : Block
{
/// <summary>
/// Places a new timer block.
/// </summary>
public static Timer PlaceNew(float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
EGID id = PlacementEngine.PlaceBlock(BlockIDs.Timer, color, darkness,
position, uscale, scale, player, rotation);
return new Timer(id);
}
return null;
}
public Timer(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists<TimerBlockDataStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
public Timer(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TIMER_BLOCK_GROUP))
{
if (!BlockEngine.GetBlockInfoExists<TimerBlockDataStruct>(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
// custom timer properties
/// <summary>
/// The player-specified start time.
/// </summary>
public float Start
{
get
{
return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).startTime;
}
set
{
ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
tbds.startTime = value;
}
}
/// <summary>
/// The player-specified end time.
/// </summary>
public float End
{
get
{
return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).endTime;
}
set
{
ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
tbds.endTime = value;
}
}
/// <summary>
/// Whether to display time with millisecond precision.
/// </summary>
public bool DisplayMilliseconds
{
get
{
return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).outputFormatHasMS;
}
set
{
ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
tbds.outputFormatHasMS = value;
}
}
/// <summary>
/// Current time (as of the last video frame), in milliseconds.
/// </summary>
public int CurrentTime
{
get
{
return BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(Id).timeLastRenderFrameMS;
}
set
{
ref TimerBlockLabelCacheEntityStruct tblces = ref BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(Id);
tblces.timeLastRenderFrameMS = value;
}
}
}
}

View file

@ -1,38 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using HarmonyLib;
using Svelto.Context;
using Svelto.ECS;
using RobocraftX;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Commands
{
/// <summary>
/// Patch of RobocraftX.GUI.CommandLine.CommandLineCompositionRoot.Compose<T>()
/// </summary>
// TODO: fix
[HarmonyPatch]
//[HarmonyPatch(typeof(RobocraftX.GUI.CommandLine.CommandLineCompositionRoot))]
//[HarmonyPatch("Compose")]
//[HarmonyPatch("Compose", new Type[] { typeof(UnityContext<FullGameCompositionRoot>), typeof(EnginesRoot), typeof(World), typeof(Action), typeof(MultiplayerInitParameters), typeof(StateSyncRegistrationHelper)})]
static class CommandPatch
{
public static void Postfix(EnginesRoot enginesRoot)
{
// When a game is loaded, register the command engines
CommandManager.RegisterEngines(enginesRoot);
}
public static MethodBase TargetMethod(Harmony instance)
{
return typeof(RobocraftX.GUI.CommandLine.CommandLineCompositionRoot).GetMethod("Compose").MakeGenericMethod(typeof(object));
//return func.Method;
}
}
}

View file

@ -1,42 +0,0 @@
using System;
using uREPL;
namespace GamecraftModdingAPI.Commands
{
public static class ExistingCommands
{
public static void Call(string commandName)
{
RuntimeCommands.Call(commandName);
}
public static void Call<Arg0>(string commandName, Arg0 arg0)
{
RuntimeCommands.Call<Arg0>(commandName, arg0);
}
public static void Call<Arg0, Arg1>(string commandName, Arg0 arg0, Arg1 arg1)
{
RuntimeCommands.Call<Arg0, Arg1>(commandName, arg0, arg1);
}
public static void Call<Arg0, Arg1, Arg2>(string commandName, Arg0 arg0, Arg1 arg1, Arg2 arg2)
{
RuntimeCommands.Call<Arg0, Arg1, Arg2>(commandName, arg0, arg1, arg2);
}
public static bool Exists(string commandName)
{
return RuntimeCommands.HasRegistered(commandName);
}
public static string[] GetCommandNames()
{
var keys = RuntimeCommands.table.Keys;
string[] res = new string[keys.Count];
keys.CopyTo(res, 0);
return res;
}
}
}

View file

@ -1,46 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using Svelto.ECS;
using RobocraftX.Common;
using RobocraftX.StateSync;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Patch of RobocraftX.StateSync.DeterministicStepCompositionRoot.ComposeEnginesGroups(...)
/// </summary>
//[HarmonyPatch(typeof(DeterministicStepCompositionRoot), "DeterministicCompose")]
[HarmonyPatch]
class GameHostTransitionDeterministicGroupEnginePatch
{
public static readonly GameStateBuildEmitterEngine buildEngine = new GameStateBuildEmitterEngine();
public static readonly GameStateSimulationEmitterEngine simEngine = new GameStateSimulationEmitterEngine();
public static void Postfix()
{
//stateSyncReg.buildModeInitializationEngines.Add(buildEngine);
//stateSyncReg.simulationModeInitializationEngines.Add(simEngine);
//enginesRoot.AddEngine(buildEngine);
//enginesRoot.AddEngine(simEngine);
buildEngine.EmitIfBuildMode();
simEngine.EmitIfSimMode();
}
[HarmonyTargetMethod]
public static MethodBase TargetMethod(Harmony harmonyInstance)
{
return AccessTools.Method(AccessTools.TypeByName("RobocraftX.StateSync.GameHostTransitionDeterministicGroupEngine"), "EndTransition");
//.MakeGenericMethod(typeof(CosmeticEnginesSequenceBuildOrder), typeof(CosmeticEnginesSequenceSimOrder), typeof(DeterministicToCosmeticSyncBuildOrder), typeof(DeterministicToCosmeticSyncSimOrder));
}
}
}

View file

@ -1,105 +0,0 @@
using System;
using Svelto.ECS;
namespace GamecraftModdingAPI.Events
{
public class EmitterBuilder
{
private string name;
private int? type;
/// <summary>
/// Create a new event emitter builder.
/// </summary>
public EmitterBuilder()
{
}
/// <summary>
/// Create a new event emitter builder.
/// This is equivalent to new <code>EmitterBuilder().Name(name)</code>
/// </summary>
/// <param name="name">The emitter name.</param>
public EmitterBuilder(string name)
{
this.name = name;
}
/// <summary>
/// Create and return an event emitter builder.
/// </summary>
/// <returns>The builder.</returns>
public static EmitterBuilder Builder()
{
return new EmitterBuilder();
}
/// <summary>
/// Create and return an event emitter builder.
/// This is equivalent to <code>Builder().Name(name)</code>
/// </summary>
/// <returns>The builder.</returns>
/// <param name="name">The emitter name.</param>
public static EmitterBuilder Builder(string name)
{
return new EmitterBuilder(name);
}
/// <summary>
/// Name the event emitter.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="name">The event emitter name.</param>
public EmitterBuilder Name(string name)
{
this.name = name;
return this;
}
/// <summary>
/// Set the type of event to handle.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="eventType">The event type.</param>
public EmitterBuilder Handle(EventType eventType)
{
return Handle((int)eventType);
}
/// <summary>
/// Set the type of event to handle.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="eventType">The event type.</param>
public EmitterBuilder Handle(int eventType)
{
this.type = eventType;
return this;
}
/// <summary>
/// Build the event emitter.
/// </summary>
/// <returns>The event emitter.</returns>
/// <param name="register">Automatically register the event emitter with EventManager.AddEventemitter().</param>
public IEventEmitterEngine Build(bool register = true)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new EventParameterMissingException("Event emitter name must be defined before Build() is called");
}
if (!type.HasValue)
{
throw new EventParameterMissingException("Event emitter event type must be defined before Build() is called");
}
SimpleEventEmitterEngine result = new SimpleEventEmitterEngine(type.Value, name);
if (register)
{
EventManager.AddEventEmitter(result);
}
return result;
}
}
}

View file

@ -1,60 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Convenient factories for mod event engines
/// </summary>
public static class EventEngineFactory
{
/// <summary>
/// Factory method which automatically adds the SimpleEventHandlerEngine to the Manager
/// </summary>
/// <param name="name">The name of the engine</param>
/// <param name="type">The type of event to handle</param>
/// <param name="onActivated">The operation to do when the event is created</param>
/// <param name="onDestroyed">The operation to do when the event is destroyed (if applicable)</param>
/// <returns>The created object</returns>
public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, int type, Action onActivated, Action onDestroyed)
{
var engine = new SimpleEventHandlerEngine(onActivated, onDestroyed, type, name);
EventManager.AddEventHandler(engine);
return engine;
}
/// <summary>
/// Factory method which automatically adds the SimpleEventHandlerEngine to the Manager
/// </summary>
/// <param name="name">The name of the engine</param>
/// <param name="type">The type of event to handle</param>
/// <param name="onActivated">The operation to do when the event is created</param>
/// <param name="onDestroyed">The operation to do when the event is destroyed (if applicable)</param>
/// <returns>The created object</returns>
public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, int type, Action<EntitiesDB> onActivated, Action<EntitiesDB> onDestroyed)
{
var engine = new SimpleEventHandlerEngine(onActivated, onDestroyed, type, name);
EventManager.AddEventHandler(engine);
return engine;
}
/// <summary>
/// Factory method which automatically adds the SimpleEventEmitterEngine to the Manager
/// </summary>
/// <param name="name">The name of the engine</param>
/// <param name="type">The type of event to emit</param>
/// <param name="isRemovable">Will removing this engine not break your code?</param>
/// <returns>The created object</returns>
public static SimpleEventEmitterEngine CreateAddSimpleEmitter(string name, int type, bool isRemovable = true)
{
var engine = new SimpleEventEmitterEngine(type, name, isRemovable);
EventManager.AddEventEmitter(engine);
return engine;
}
}
}

View file

@ -1,66 +0,0 @@
using System;
namespace GamecraftModdingAPI.Events
{
public class EventException : GamecraftModdingAPIException
{
public EventException()
{
}
public EventException(string message) : base(message)
{
}
public EventException(string message, Exception innerException) : base(message, innerException)
{
}
}
public class EventNotFoundException : EventException
{
public EventNotFoundException()
{
}
public EventNotFoundException(string message) : base(message)
{
}
}
public class EventAlreadyExistsException : EventException
{
public EventAlreadyExistsException()
{
}
public EventAlreadyExistsException(string message) : base(message)
{
}
}
public class EventRuntimeException : EventException
{
public EventRuntimeException()
{
}
public EventRuntimeException(string message) : base(message)
{
}
public EventRuntimeException(string message, Exception innerException) : base(message, innerException)
{
}
}
public class EventParameterMissingException : EventException
{
public EventParameterMissingException()
{
}
public EventParameterMissingException(string message) : base(message)
{
}
}
}

View file

@ -1,128 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Keeps track of event handlers and emitters.
/// This is used to add, remove and get API event handlers and emitters.
/// </summary>
public static class EventManager
{
private static Dictionary<string, IEventEmitterEngine> _eventEmitters = new Dictionary<string, IEventEmitterEngine>();
private static Dictionary<string, IEventHandlerEngine> _eventHandlers = new Dictionary<string, IEventHandlerEngine>();
private static EnginesRoot _lastEngineRoot;
// event handler management
public static void AddEventHandler(IEventHandlerEngine engine)
{
if (ExistsEventHandler(engine))
{
throw new EventAlreadyExistsException($"IEventHandlerEngine {engine.Name} already exists");
}
_eventHandlers[engine.Name] = engine;
if (_lastEngineRoot != null)
{
Logging.MetaDebugLog($"Registering IEventHandlerEngine {engine.Name}");
_lastEngineRoot.AddEngine(engine);
}
}
public static bool ExistsEventHandler(string name)
{
return _eventHandlers.ContainsKey(name);
}
public static bool ExistsEventHandler(IEventHandlerEngine engine)
{
return ExistsEventHandler(engine.Name);
}
public static IEventHandlerEngine GetEventHandler(string name)
{
return _eventHandlers[name];
}
public static string[] GetEventHandlerNames()
{
return _eventHandlers.Keys.ToArray();
}
public static void RemoveEventHandler(string name)
{
_eventHandlers.Remove(name);
}
// event emitter management
public static void AddEventEmitter(IEventEmitterEngine engine)
{
if (ExistsEventEmitter(engine))
{
throw new EventAlreadyExistsException($"IEventEmitterEngine {engine.Name} already exists");
}
_eventEmitters[engine.Name] = engine;
if (_lastEngineRoot != null)
{
Logging.MetaDebugLog($"Registering IEventEmitterEngine {engine.Name}");
_lastEngineRoot.AddEngine(engine);
}
}
public static bool ExistsEventEmitter(string name)
{
return _eventEmitters.ContainsKey(name);
}
public static bool ExistsEventEmitter(IEventEmitterEngine engine)
{
return ExistsEventEmitter(engine.Name);
}
public static IEventEmitterEngine GetEventEmitter(string name)
{
return _eventEmitters[name];
}
public static string[] GetEventEmitterNames()
{
return _eventEmitters.Keys.ToArray();
}
public static void RemoveEventEmitter(string name)
{
if (_eventEmitters[name].isRemovable)
{
_eventEmitters.Remove(name);
}
}
public static void RegisterEngines(EnginesRoot enginesRoot)
{
_lastEngineRoot = enginesRoot;
// Register handlers before emitters so no events are missed
var entityFactory = enginesRoot.GenerateEntityFactory();
foreach (var key in _eventHandlers.Keys)
{
Logging.MetaDebugLog($"Registering IEventHandlerEngine {_eventHandlers[key].Name}");
enginesRoot.AddEngine(_eventHandlers[key]);
}
foreach (var key in _eventEmitters.Keys)
{
Logging.MetaDebugLog($"Registering IEventEmitterEngine {_eventEmitters[key].Name}");
_eventEmitters[key].Factory = entityFactory;
enginesRoot.AddEngine(_eventEmitters[key]);
}
}
}
}

View file

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Built-in event types.
/// These are configured to fire when the API is initialized.
/// </summary>
public enum EventType
{
ApplicationInitialized,
Menu,
MenuSwitchedTo,
Game,
GameReloaded,
GameSwitchedTo,
SimulationSwitchedTo,
BuildSwitchedTo
}
}

View file

@ -1,60 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using RobocraftX.CR.MainGame;
using Svelto.ECS;
using Unity.Entities;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
/// </summary>
[HarmonyPatch]
class GameActivatedComposePatch
{
public static bool IsGameSwitching = false;
public static bool IsGameReloading = false;
public static void Postfix(ref object contextHolder, ref EnginesRoot enginesRoot, World physicsWorld)
{
// register custom game engines
GameEngineManager.RegisterEngines(enginesRoot);
// initialize AsyncUtils
AsyncUtils.Setup(enginesRoot);
// initialize Block
Block.Setup(physicsWorld);
// A new EnginesRoot is always created when ActivateGame is called
// so all event emitters and handlers must be re-registered.
EventManager.RegisterEngines(enginesRoot);
Logging.Log("Dispatching Game Activated event");
EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
if (IsGameSwitching)
{
IsGameSwitching = false;
Logging.Log("Dispatching Game Switched To event");
EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
}
if (IsGameReloading)
{
IsGameReloading = false;
Logging.Log("Dispatching Game Reloaded event");
EventManager.GetEventEmitter("GamecraftModdingAPIGameReloadedEventEmitter").Emit();
}
}
public static MethodBase TargetMethod()
{
return typeof(MainGameCompositionRoot).GetMethods().First(m => m.Name == "Compose")
.MakeGenericMethod(typeof(object));
}
}
}

View file

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using RobocraftX;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Patch of RobocraftX.FullGameCompositionRoot.ReloadGame()
/// </summary>
[HarmonyPatch(typeof(FullGameCompositionRoot), "ReloadGame")]
class GameReloadedPatch
{
public static void Postfix()
{
GameActivatedComposePatch.IsGameReloading = true;
}
}
}

View file

@ -1,54 +0,0 @@
using System;
using Unity.Jobs;
using RobocraftX.SimulationModeState;
using RobocraftX.StateSync;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Event emitter engine for switching to to build mode.
/// </summary>
public class GameStateBuildEmitterEngine : IEventEmitterEngine, IUnorderedInitializeOnTimeStoppedModeEntered
{
public string Name { get; } = "GamecraftModdingAPIGameStateBuildEventEmitter" ;
public EntitiesDB entitiesDB { set; private get; }
public int type { get; } = (int)EventType.BuildSwitchedTo;
public bool isRemovable { get; } = false;
public IEntityFactory Factory { set; private get; }
public void Dispose() { }
public void Emit()
{
Logging.Log("Dispatching Build Switched To event");
if (Factory == null) { return; }
Factory.BuildEntity<ModEventEntityDescriptor>(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup)
.Init(new ModEventEntityStruct { type = type });
}
public void EmitIfBuildMode()
{
//Logging.MetaDebugLog($"nextSimulationMode: {entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP).nextSimulationMode}");
if (entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP).nextSimulationMode == SimulationMode.TimeStopped)
{
Emit();
}
}
public JobHandle OnInitializeTimeStoppedMode(JobHandle inputDeps)
{
Emit();
return inputDeps;
}
public void Ready() { }
}
}

View file

@ -1,53 +0,0 @@
using System;
using Unity.Jobs;
using RobocraftX.SimulationModeState;
using RobocraftX.StateSync;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Event emitter engine for switching to simulation mode.
/// </summary>
public class GameStateSimulationEmitterEngine : IEventEmitterEngine, IUnorderedInitializeOnTimeRunningModeEntered
{
public string Name { get; } = "GamecraftModdingAPIGameStateSimulationEventEmitter" ;
public EntitiesDB entitiesDB { set; private get; }
public int type { get; } = (int)EventType.SimulationSwitchedTo;
public bool isRemovable { get; } = false;
public IEntityFactory Factory { set; private get; }
public void Dispose() { }
public void Emit()
{
Logging.Log("Dispatching Simulation Switched To event");
if (Factory == null) { return; }
Factory.BuildEntity<ModEventEntityDescriptor>(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup)
.Init(new ModEventEntityStruct { type = type });
}
public void EmitIfSimMode()
{
if (entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP).nextSimulationMode == SimulationMode.TimeRunning)
{
Emit();
}
}
public JobHandle OnInitializeTimeRunningMode(JobHandle inputDeps)
{
Emit();
return inputDeps;
}
public void Ready() { }
}
}

View file

@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using HarmonyLib;
using RobocraftX;
using RobocraftX.CR.MainGame;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
/// (scheduled for execution during RobocraftX.FullGameCompositionRoot.SwitchToGame())
/// </summary>
[HarmonyPatch(typeof(FullGameCompositionRoot), "SwitchToGame")]
class GameSwitchedToPatch
{
public static void Prefix()
{
GameActivatedComposePatch.IsGameSwitching = true;
}
}
}

View file

@ -1,165 +0,0 @@
using System;
using Svelto.ECS;
namespace GamecraftModdingAPI.Events
{
public class HandlerBuilder
{
private string name;
private int? type;
private Action<EntitiesDB> activated;
private Action<EntitiesDB> destroyed;
/// <summary>
/// Create a new event handler builder.
/// </summary>
public HandlerBuilder()
{
}
/// <summary>
/// Create a new event handler builder.
/// This is equivalent to new <code>HandlerBuilder().Name(name)</code>
/// </summary>
/// <param name="name">The handler name.</param>
public HandlerBuilder(string name)
{
this.name = name;
}
/// <summary>
/// Create and return an event handler builder.
/// </summary>
/// <returns>The builder.</returns>
public static HandlerBuilder Builder()
{
return new HandlerBuilder();
}
/// <summary>
/// Create and return an event handler builder.
/// This is equivalent to <code>Builder().Name(name)</code>
/// </summary>
/// <returns>The builder.</returns>
/// <param name="name">The handler name.</param>
public static HandlerBuilder Builder(string name)
{
return new HandlerBuilder(name);
}
/// <summary>
/// Name the event handler.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="name">The event handler name.</param>
public HandlerBuilder Name(string name)
{
this.name = name;
return this;
}
/// <summary>
/// Set the action to perform on when the activated event occurs.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="action">The activated event action.</param>
public HandlerBuilder OnActivation(Action action)
{
return OnActivation((_) => { action(); });
}
/// <summary>
/// Set the action to perform on when the activated event occurs.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="action">The activated event action.</param>
public HandlerBuilder OnActivation(Action<EntitiesDB> action)
{
this.activated = action;
return this;
}
/// <summary>
/// Set the action to perform when the destroyed event occurs.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="action">The destroyed event action.</param>
public HandlerBuilder OnDestruction(Action action)
{
return OnDestruction((_) => { action(); });
}
/// <summary>
/// Set the action to perform when the destroyed event occurs.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="action">The destroyed event action.</param>
public HandlerBuilder OnDestruction(Action<EntitiesDB> action)
{
this.destroyed = action;
return this;
}
/// <summary>
/// Set the type of event to handle.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="eventType">The event type.</param>
public HandlerBuilder Handle(EventType eventType)
{
return Handle((int)eventType);
}
/// <summary>
/// Set the type of event to handle.
/// </summary>
/// <returns>The builder.</returns>
/// <param name="eventType">The event type.</param>
public HandlerBuilder Handle(int eventType)
{
this.type = eventType;
return this;
}
/// <summary>
/// Build the event handler.
/// </summary>
/// <returns>The event handler.</returns>
/// <param name="register">Automatically register the event handler with EventManager.AddEventHandler().</param>
public IEventHandlerEngine Build(bool register = true)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new EventParameterMissingException("Event handler name must be defined before Build() is called");
}
if (activated == null && destroyed == null)
{
throw new EventParameterMissingException("Event handler destruction or activated event action must be defined before Build() is called");
}
if (!type.HasValue)
{
throw new EventParameterMissingException("Event handler event type must be defined before Build() is called");
}
Action<EntitiesDB> validActivated = activated;
if (validActivated == null)
{
validActivated = (_) => { };
}
Action<EntitiesDB> validDestroyed = destroyed;
if (validDestroyed == null)
{
validDestroyed = (_) => { };
}
SimpleEventHandlerEngine result = new SimpleEventHandlerEngine(validActivated, validDestroyed, type.Value, name);
if (register)
{
EventManager.AddEventHandler(result);
}
return result;
}
}
}

View file

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
using GamecraftModdingAPI.Engines;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Engine interface to create a ModEventEntityStruct in entitiesDB when a specific event occurs.
/// </summary>
public interface IEventEmitterEngine : IFactoryEngine
{
/// <summary>
/// Emit the event. (Optional)
/// </summary>
void Emit();
}
}

View file

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
using Svelto.ECS.Internal;
using GamecraftModdingAPI.Engines;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Engine interface to handle ModEventEntityStruct events emitted by IEventEmitterEngines.
/// </summary>
public interface IEventHandlerEngine : IReactionaryEngine<ModEventEntityStruct>
{
}
}

View file

@ -1,42 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using RobocraftX;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateMenu()
/// </summary>
[HarmonyPatch(typeof(FullGameCompositionRoot), "ActivateMenu")]
class MenuActivatedPatch
{
private static bool firstLoad = true;
public static void Postfix(ref EnginesRoot ____frontEndEnginesRoot, FullGameCompositionRoot __instance)
{
// register custom menu engines
MenuEngineManager.RegisterEngines(____frontEndEnginesRoot);
// A new EnginesRoot is always created when ActivateMenu is called
// so all event emitters and handlers must be re-registered.
EventManager.RegisterEngines(____frontEndEnginesRoot);
if (firstLoad)
{
firstLoad = false;
FullGameFields.Init(__instance);
//Application.Application.SetFullGameCompositionRoot(__instance);
Logging.Log("Dispatching App Init event");
EventManager.GetEventEmitter("GamecraftModdingAPIApplicationInitializedEventEmitter").Emit();
}
Logging.Log("Dispatching Menu Activated event");
EventManager.GetEventEmitter("GamecraftModdingAPIMenuActivatedEventEmitter").Emit();
}
}
}

View file

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using RobocraftX;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// Patch of RobocraftX.FullGameCompositionRoot.SwitchToMenu()
/// </summary>
[HarmonyPatch(typeof(FullGameCompositionRoot), "SwitchToMenu")]
class MenuSwitchedToPatch
{
public static void Postfix()
{
// Event emitters and handlers should already be registered by MenuActivated event
Logging.Log("Dispatching Menu Switched To event");
EventManager.GetEventEmitter("GamecraftModdingAPIMenuSwitchedToEventEmitter").Emit();
}
}
}

View file

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// EntityDescriptor for creating ModEventEntityStructs
/// </summary>
public class ModEventEntityDescriptor : GenericEntityDescriptor<ModEventEntityStruct>
{
}
}

View file

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// The event entity struct
/// </summary>
public struct ModEventEntityStruct : IEntityComponent, INeedEGID
{
/// <summary>
/// The type of event that has been emitted
/// </summary>
public int type;
public EGID ID { get; set; }
}
}

View file

@ -1,65 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// A simple implementation of IEventEmitterEngine sufficient for most uses
/// </summary>
public class SimpleEventEmitterEngine : IEventEmitterEngine
{
public string Name { get; set; }
public int type { get; set; }
public bool isRemovable { get; }
public IEntityFactory Factory { private get; set; }
public EntitiesDB entitiesDB { set; private get; }
public void Ready() { }
/// <summary>
/// Emit the event
/// </summary>
public void Emit()
{
Factory.BuildEntity<ModEventEntityDescriptor>(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup)
.Init(new ModEventEntityStruct { type = type });
}
public void Dispose() { }
/// <summary>
/// Construct the engine
/// </summary>
/// <param name="type">The EventType to use for ModEventEntityStruct.type</param>
/// <param name="name">The name of this engine</param>
/// <param name="isRemovable">Will removing this engine not break your code?</param>
public SimpleEventEmitterEngine(EventType type, string name, bool isRemovable = true)
{
this.type = (int)type;
this.Name = name;
this.isRemovable = isRemovable;
}
/// <summary>
/// Construct the engine
/// </summary>
/// <param name="type">The object to use for ModEventEntityStruct.type</param>
/// <param name="name">The name of this engine</param>
/// <param name="isRemovable">Will removing this engine not break your code?</param>
public SimpleEventEmitterEngine(int type, string name, bool isRemovable = true)
{
this.type = type;
this.Name = name;
this.isRemovable = isRemovable;
}
}
}

View file

@ -1,145 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
/// <summary>
/// A simple implementation of IEventHandlerEngine sufficient for most uses
/// </summary>
public class SimpleEventHandlerEngine : IEventHandlerEngine
{
public int type { get; set; }
public string Name { get; set; }
private bool isActivated = false;
private bool jankActivateFix = false;
private bool jankDestroyFix = false;
private readonly Action<EntitiesDB> onActivated;
private readonly Action<EntitiesDB> onDestroyed;
public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => true;
public void Add(ref ModEventEntityStruct entityView, EGID egid)
{
if (entityView.type.Equals(this.type))
{
jankActivateFix = !jankActivateFix;
if (jankActivateFix) return;
isActivated = true;
onActivatedInvokeCatchError(entitiesDB);
}
}
/// <summary>
/// Manually activate the EventHandler.
/// Once activated, the next remove event will not be ignored.
/// </summary>
/// <param name="handle">Whether to invoke the activated action</param>
public void Activate(bool handle = false)
{
isActivated = true;
if (handle && entitiesDB != null)
{
onActivatedInvokeCatchError(entitiesDB);
}
}
public void Deactivate()
{
isActivated = false;
}
public void Ready() { }
public void Remove(ref ModEventEntityStruct entityView, EGID egid)
{
if (entityView.type.Equals(this.type) && isActivated)
{
jankDestroyFix = !jankDestroyFix;
if (jankDestroyFix) return;
isActivated = false;
onDestroyedInvokeCatchError(entitiesDB);
}
}
public void Dispose()
{
if (isActivated)
{
isActivated = false;
onDestroyedInvokeCatchError(entitiesDB);
}
}
/// <summary>
/// Construct the engine
/// </summary>
/// <param name="activated">The operation to do when the event is created</param>
/// <param name="removed">The operation to do when the event is destroyed (if applicable)</param>
/// <param name="type">The type of event to handle</param>
/// <param name="name">The name of the engine</param>
/// <param name="simple">A useless parameter to use to avoid Python overload resolution errors</param>
public SimpleEventHandlerEngine(Action activated, Action removed, int type, string name, bool simple = true)
: this((EntitiesDB _) => { activated.Invoke(); }, (EntitiesDB _) => { removed.Invoke(); }, type, name) { }
/// <summary>
/// Construct the engine
/// </summary>
/// <param name="activated">The operation to do when the event is created</param>
/// <param name="removed">The operation to do when the event is destroyed (if applicable)</param>
/// <param name="type">The type of event to handler</param>
/// <param name="name">The name of the engine</param>
public SimpleEventHandlerEngine(Action<EntitiesDB> activated, Action<EntitiesDB> removed, int type, string name)
{
this.type = type;
this.Name = name;
this.onActivated = activated;
this.onDestroyed = removed;
}
private void onActivatedInvokeCatchError(EntitiesDB _entitiesDB)
{
try
{
onActivated.Invoke(_entitiesDB);
}
catch (Exception e)
{
EventRuntimeException wrappedException = new EventRuntimeException($"EventHandler {Name} threw an exception when activated", e);
Logging.LogWarning(wrappedException.ToString());
}
}
private void onDestroyedInvokeCatchError(EntitiesDB _entitiesDB)
{
try
{
onDestroyed.Invoke(_entitiesDB);
}
catch (Exception e)
{
EventRuntimeException wrappedException = new EventRuntimeException($"EventHandler {Name} threw an exception when destroyed", e);
Logging.LogWarning(wrappedException.ToString());
}
}
public SimpleEventHandlerEngine(Action activated, Action removed, EventType type, string name, bool simple = true)
: this((EntitiesDB _) => { activated.Invoke(); }, (EntitiesDB _) => { removed.Invoke(); }, (int)type, name) { }
public SimpleEventHandlerEngine(Action<EntitiesDB> activated, Action<EntitiesDB> removed, EventType type, string name, bool simple = true)
: this(activated, removed, (int)type, name) { }
}
}

View file

@ -1,868 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.4.0-preview</Version>
<Authors>Exmods</Authors>
<PackageLicenseExpression>GNU General Public Licence 3+</PackageLicenseExpression>
<PackageProjectUrl>https://git.exmods.org/modtainers/GamecraftModdingAPI</PackageProjectUrl>
<NeutralLanguage>en-CA</NeutralLanguage>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Test|AnyCPU' ">
<DefineConstants>DEBUG;TEST;TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.0.0.10" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<!--Start Dependencies-->
<ItemGroup>
<Reference Include="Analytics">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Analytics.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Analytics.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Authentication">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Authentication.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Authentication.dll</HintPath>
</Reference>
<Reference Include="BlockEntityFactory">
<HintPath>..\ref\GamecraftPreview_Data\Managed\BlockEntityFactory.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\BlockEntityFactory.dll</HintPath>
</Reference>
<Reference Include="Blocks.HUDFeedbackBlocks">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath>
</Reference>
<Reference Include="CommandLine">
<HintPath>..\ref\GamecraftPreview_Data\Managed\CommandLine.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\CommandLine.dll</HintPath>
</Reference>
<Reference Include="DataLoader">
<HintPath>..\ref\GamecraftPreview_Data\Managed\DataLoader.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\DataLoader.dll</HintPath>
</Reference>
<Reference Include="DDNA">
<HintPath>..\ref\GamecraftPreview_Data\Managed\DDNA.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\DDNA.dll</HintPath>
</Reference>
<Reference Include="FMOD">
<HintPath>..\ref\GamecraftPreview_Data\Managed\FMOD.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\FMOD.dll</HintPath>
</Reference>
<Reference Include="FullGame">
<HintPath>..\ref\GamecraftPreview_Data\Managed\FullGame.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\FullGame.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.AudioBlocks">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.AudioBlocks.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.AudioBlocks.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Blocks.ConsoleBlock">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.ConsoleBlock.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.ConsoleBlock.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Blocks.DamagingSurfaceBlock">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.DamagingSurfaceBlock.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.DamagingSurfaceBlock.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Blocks.GenericPhysicsBlocks">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.GenericPhysicsBlocks.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.GenericPhysicsBlocks.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Blocks.LogicBlock">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.LogicBlock.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.LogicBlock.dll</HintPath>
</Reference>
<Reference Include="GameCraft.Blocks.ProjectileBlock">
<HintPath>..\ref\GamecraftPreview_Data\Managed\GameCraft.Blocks.ProjectileBlock.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\GameCraft.Blocks.ProjectileBlock.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Blocks.TimerBlock">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.TimerBlock.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.TimerBlock.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.CharacterVulnerability">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.CharacterVulnerability.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.CharacterVulnerability.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.CharacterVulnerabilityGui">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.CharacterVulnerabilityGui.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.CharacterVulnerabilityGui.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Effects">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Effects.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Effects.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.GUI.ConsoleBlock">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.ConsoleBlock.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.ConsoleBlock.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.GUI.GraphicsScreen">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.GraphicsScreen.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.GraphicsScreen.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.GUI.HUDFeedbackBlocks">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.HUDFeedbackBlocks.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.HUDFeedbackBlocks.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.GUI.Tweaks">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.Tweaks.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.Tweaks.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.GUI.Wires">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.Wires.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.Wires.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.GUI.Wires.Mockup">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.Wires.Mockup.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.Wires.Mockup.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.GUI.WorldSpaceGuis">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.WorldSpaceGuis.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.WorldSpaceGuis.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Music">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Music.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Music.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.PerformanceWarnings">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.PerformanceWarnings.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.PerformanceWarnings.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Tweaks">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Tweaks.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Tweaks.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Tweaks.Mockup">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Tweaks.Mockup.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Tweaks.Mockup.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.VisualEffects">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.VisualEffects.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.VisualEffects.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Wires">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Wires.Input">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.Input.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.Input.dll</HintPath>
</Reference>
<Reference Include="Gamecraft.Wires.Mockup">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.Mockup.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.Mockup.dll</HintPath>
</Reference>
<Reference Include="GameState">
<HintPath>..\ref\GamecraftPreview_Data\Managed\GameState.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\GameState.dll</HintPath>
</Reference>
<Reference Include="GPUInstancer">
<HintPath>..\ref\GamecraftPreview_Data\Managed\GPUInstancer.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\GPUInstancer.dll</HintPath>
</Reference>
<Reference Include="Havok.Physics">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Havok.Physics.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Havok.Physics.dll</HintPath>
</Reference>
<Reference Include="Havok.Physics.Hybrid">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Havok.Physics.Hybrid.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Havok.Physics.Hybrid.dll</HintPath>
</Reference>
<Reference Include="LZ4">
<HintPath>..\ref\GamecraftPreview_Data\Managed\LZ4.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\LZ4.dll</HintPath>
</Reference>
<Reference Include="MultiplayerNetworking">
<HintPath>..\ref\GamecraftPreview_Data\Managed\MultiplayerNetworking.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\MultiplayerNetworking.dll</HintPath>
</Reference>
<Reference Include="MultiplayerTest">
<HintPath>..\ref\GamecraftPreview_Data\Managed\MultiplayerTest.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\MultiplayerTest.dll</HintPath>
</Reference>
<Reference Include="RCX.ScreenshotTaker">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RCX.ScreenshotTaker.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RCX.ScreenshotTaker.dll</HintPath>
</Reference>
<Reference Include="RobocraftECS">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftECS.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftECS.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.AccountPreferences">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.AccountPreferences.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.AccountPreferences.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Blocks">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Blocks.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Blocks.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Blocks.Ghost">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Blocks.Ghost.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Blocks.Ghost.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Blocks.Triggers">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Blocks.Triggers.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Blocks.Triggers.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Building.BoxSelect">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Building.BoxSelect.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Building.BoxSelect.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Building.Jobs">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Building.Jobs.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Building.Jobs.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Character">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Character.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Character.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.ClusterToWireConversion">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.ClusterToWireConversion.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.ClusterToWireConversion.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Common">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Common.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Common.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.ControlsScreen">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.ControlsScreen.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.ControlsScreen.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Crosshair">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Crosshair.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Crosshair.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.FrontEnd">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.FrontEnd.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.FrontEnd.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.GUI.BlockLabel">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.BlockLabel.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.BlockLabel.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.GUI.DebugDisplay">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.DebugDisplay.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.DebugDisplay.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.GUI">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.GUI.RemoveBlock">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.RemoveBlock.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.RemoveBlock.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.GUI.ScaleGhost">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.ScaleGhost.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUI.ScaleGhost.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.GUIs.WorkshopPrefabs">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUIs.WorkshopPrefabs.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.GUIs.WorkshopPrefabs.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Input">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Input.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Input.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.MachineEditor">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.MachineEditor.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.MachineEditor.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.MainGame">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.MainGame.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.MainGame.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.MainSimulation">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.MainSimulation.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.MainSimulation.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.MockCharacter">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.MockCharacter.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.MockCharacter.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Multiplayer">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Multiplayer.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Multiplayer.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Multiplayer.NetworkEntityStream">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Multiplayer.NetworkEntityStream.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Multiplayer.NetworkEntityStream.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.MultiplayerInput">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.MultiplayerInput.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.MultiplayerInput.dll</HintPath>
</Reference>
<Reference Include="Robocraftx.ObjectIdBlocks">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Robocraftx.ObjectIdBlocks.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Robocraftx.ObjectIdBlocks.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Party">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Party.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Party.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.PartyGui">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.PartyGui.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.PartyGui.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Physics">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Physics.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Physics.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.PilotSeat">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.PilotSeat.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.PilotSeat.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Player">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Player.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Player.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Rendering">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Rendering.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Rendering.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Rendering.Mock">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Rendering.Mock.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Rendering.Mock.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.SaveAndLoad">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.SaveAndLoad.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.SaveAndLoad.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.SaveGameDialog">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.SaveGameDialog.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.SaveGameDialog.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Serializers">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Serializers.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Serializers.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Services">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.Services.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.Services.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.SignalHandling">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.SignalHandling.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.SignalHandling.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.StateSync">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX.StateSync.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX.StateSync.dll</HintPath>
</Reference>
<Reference Include="RobocraftX_SpawnPoints">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX_SpawnPoints.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX_SpawnPoints.dll</HintPath>
</Reference>
<Reference Include="RobocraftX_TextBlock">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocraftX_TextBlock.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocraftX_TextBlock.dll</HintPath>
</Reference>
<Reference Include="RobocratX.SimulationCompositionRoot">
<HintPath>..\ref\GamecraftPreview_Data\Managed\RobocratX.SimulationCompositionRoot.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\RobocratX.SimulationCompositionRoot.dll</HintPath>
</Reference>
<Reference Include="StringFormatter">
<HintPath>..\ref\GamecraftPreview_Data\Managed\StringFormatter.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\StringFormatter.dll</HintPath>
</Reference>
<Reference Include="Svelto.Common_3">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Svelto.Common_3.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Svelto.Common_3.dll</HintPath>
</Reference>
<Reference Include="Svelto.ECS">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Svelto.ECS.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Svelto.ECS.dll</HintPath>
</Reference>
<Reference Include="Svelto.Services">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Svelto.Services.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Svelto.Services.dll</HintPath>
</Reference>
<Reference Include="Svelto.Tasks">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Svelto.Tasks.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Svelto.Tasks.dll</HintPath>
</Reference>
<Reference Include="Unity.Addressables">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Addressables.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Addressables.dll</HintPath>
</Reference>
<Reference Include="Unity.Animation.Curves">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Animation.Curves.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Animation.Curves.dll</HintPath>
</Reference>
<Reference Include="Unity.Animation.Curves.Hybrid">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Animation.Curves.Hybrid.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Animation.Curves.Hybrid.dll</HintPath>
</Reference>
<Reference Include="Unity.Animation.DefaultGraphPipeline">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Animation.DefaultGraphPipeline.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Animation.DefaultGraphPipeline.dll</HintPath>
</Reference>
<Reference Include="Unity.Animation.DefaultGraphPipeline.Hybrid">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Animation.DefaultGraphPipeline.Hybrid.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Animation.DefaultGraphPipeline.Hybrid.dll</HintPath>
</Reference>
<Reference Include="Unity.Animation">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Animation.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Animation.dll</HintPath>
</Reference>
<Reference Include="Unity.Animation.Graph">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Animation.Graph.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Animation.Graph.dll</HintPath>
</Reference>
<Reference Include="Unity.Animation.Hybrid">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Animation.Hybrid.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Animation.Hybrid.dll</HintPath>
</Reference>
<Reference Include="Unity.Build.SlimPlayerRuntime">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Build.SlimPlayerRuntime.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Build.SlimPlayerRuntime.dll</HintPath>
</Reference>
<Reference Include="Unity.Burst">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Burst.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Burst.dll</HintPath>
</Reference>
<Reference Include="Unity.Collections">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Collections.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Collections.dll</HintPath>
</Reference>
<Reference Include="Unity.DataFlowGraph">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.DataFlowGraph.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.DataFlowGraph.dll</HintPath>
</Reference>
<Reference Include="Unity.Deformations">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Deformations.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Deformations.dll</HintPath>
</Reference>
<Reference Include="Unity.Entities">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Entities.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Entities.dll</HintPath>
</Reference>
<Reference Include="Unity.Entities.Hybrid">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Entities.Hybrid.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Entities.Hybrid.dll</HintPath>
</Reference>
<Reference Include="Unity.Jobs">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Jobs.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Jobs.dll</HintPath>
</Reference>
<Reference Include="Unity.Mathematics">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Mathematics.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Mathematics.dll</HintPath>
</Reference>
<Reference Include="Unity.Mathematics.Extensions">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Mathematics.Extensions.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Mathematics.Extensions.dll</HintPath>
</Reference>
<Reference Include="Unity.Mathematics.Extensions.Hybrid">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Mathematics.Extensions.Hybrid.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Mathematics.Extensions.Hybrid.dll</HintPath>
</Reference>
<Reference Include="Unity.MemoryProfiler">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.MemoryProfiler.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.MemoryProfiler.dll</HintPath>
</Reference>
<Reference Include="Unity.Physics">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Physics.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Physics.dll</HintPath>
</Reference>
<Reference Include="Unity.Physics.Hybrid">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Physics.Hybrid.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Physics.Hybrid.dll</HintPath>
</Reference>
<Reference Include="Unity.Platforms.Common">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Platforms.Common.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Platforms.Common.dll</HintPath>
</Reference>
<Reference Include="Unity.Postprocessing.Runtime">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Postprocessing.Runtime.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Postprocessing.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.Properties">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Properties.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Properties.dll</HintPath>
</Reference>
<Reference Include="Unity.Properties.Reflection">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Properties.Reflection.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Properties.Reflection.dll</HintPath>
</Reference>
<Reference Include="Unity.Properties.UI">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Properties.UI.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Properties.UI.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipeline.Universal.ShaderLibrary">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipeline.Universal.ShaderLibrary.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipeline.Universal.ShaderLibrary.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.Core.Runtime">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.Core.ShaderLibrary">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.Core.ShaderLibrary.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.Core.ShaderLibrary.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.Universal.Runtime">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.Universal.Runtime.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.Universal.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.Universal.Shaders">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.Universal.Shaders.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.RenderPipelines.Universal.Shaders.dll</HintPath>
</Reference>
<Reference Include="Unity.ResourceManager">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.ResourceManager.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.ResourceManager.dll</HintPath>
</Reference>
<Reference Include="Unity.Scenes.Hybrid">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Scenes.Hybrid.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Scenes.Hybrid.dll</HintPath>
</Reference>
<Reference Include="Unity.ScriptableBuildPipeline">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.ScriptableBuildPipeline.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.ScriptableBuildPipeline.dll</HintPath>
</Reference>
<Reference Include="Unity.Serialization">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Serialization.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Serialization.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="Unity.Timeline">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Timeline.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Timeline.dll</HintPath>
</Reference>
<Reference Include="Unity.Transforms">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Transforms.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Transforms.dll</HintPath>
</Reference>
<Reference Include="Unity.Transforms.Hybrid">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Transforms.Hybrid.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Transforms.Hybrid.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="uREPL">
<HintPath>..\ref\GamecraftPreview_Data\Managed\uREPL.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\uREPL.dll</HintPath>
</Reference>
<Reference Include="VisualProfiler">
<HintPath>..\ref\GamecraftPreview_Data\Managed\VisualProfiler.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\VisualProfiler.dll</HintPath>
</Reference>
<Reference Include="Accessibility">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Accessibility.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Accessibility.dll</HintPath>
</Reference>
<Reference Include="Facepunch.Steamworks.Win64">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Facepunch.Steamworks.Win64.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Facepunch.Steamworks.Win64.dll</HintPath>
</Reference>
<Reference Include="JWT">
<HintPath>..\ref\GamecraftPreview_Data\Managed\JWT.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\JWT.dll</HintPath>
</Reference>
<Reference Include="mscorlib">
<HintPath>..\ref\GamecraftPreview_Data\Managed\mscorlib.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\mscorlib.dll</HintPath>
</Reference>
<Reference Include="netstandard">
<HintPath>..\ref\GamecraftPreview_Data\Managed\netstandard.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\netstandard.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Newtonsoft.Json.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Novell.Directory.Ldap">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Novell.Directory.Ldap.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Novell.Directory.Ldap.dll</HintPath>
</Reference>
<Reference Include="Rewired_Core">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Rewired_Core.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Rewired_Core.dll</HintPath>
</Reference>
<Reference Include="Rewired_Windows">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Rewired_Windows.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Rewired_Windows.dll</HintPath>
</Reference>
<Reference Include="Unity.Burst.Unsafe">
<HintPath>..\ref\GamecraftPreview_Data\Managed\Unity.Burst.Unsafe.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\Unity.Burst.Unsafe.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AccessibilityModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.AccessibilityModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.AccessibilityModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AIModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.AIModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.AIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AndroidJNIModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.AndroidJNIModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.AndroidJNIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ARModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.ARModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.ARModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AudioModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.AudioModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.AudioModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ClothModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.ClothModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.ClothModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ClusterInputModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.ClusterInputModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.ClusterInputModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ClusterRendererModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.ClusterRendererModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.ClusterRendererModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CrashReportingModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.CrashReportingModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.CrashReportingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.DirectorModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.DirectorModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.DirectorModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.DSPGraphModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.DSPGraphModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.DSPGraphModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.GameCenterModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.GameCenterModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.GameCenterModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.GridModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.GridModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.GridModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.HotReloadModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.HotReloadModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.HotReloadModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ImageConversionModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.ImageConversionModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.ImageConversionModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.InputModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.InputModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.JSONSerializeModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.JSONSerializeModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.JSONSerializeModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.LocalizationModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.LocalizationModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.LocalizationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ParticleSystemModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.ParticleSystemModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.ParticleSystemModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PerformanceReportingModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.PerformanceReportingModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.PerformanceReportingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Physics2DModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.Physics2DModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.Physics2DModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ProfilerModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.ProfilerModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.ProfilerModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ScreenCaptureModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.ScreenCaptureModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.ScreenCaptureModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.SharedInternalsModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.SharedInternalsModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.SharedInternalsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.SpriteMaskModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.SpriteMaskModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.SpriteMaskModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.SpriteShapeModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.SpriteShapeModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.SpriteShapeModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.StreamingModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.StreamingModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.StreamingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.SubstanceModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.SubstanceModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.SubstanceModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.SubsystemsModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.SubsystemsModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.SubsystemsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TerrainModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.TerrainModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.TerrainModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TerrainPhysicsModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.TerrainPhysicsModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.TerrainPhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextCoreModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.TextCoreModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.TextCoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TilemapModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.TilemapModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.TilemapModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TLSModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.TLSModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.TLSModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIElementsModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UIElementsModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UIElementsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UIModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UmbraModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UmbraModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UmbraModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UNETModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UNETModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UNETModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityAnalyticsModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityAnalyticsModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityAnalyticsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityConnectModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityConnectModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityConnectModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityTestProtocolModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityTestProtocolModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityTestProtocolModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestAssetBundleModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestAssetBundleModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestAssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestAudioModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestAudioModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestAudioModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestTextureModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestTextureModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestTextureModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestWWWModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestWWWModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UnityWebRequestWWWModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.VehiclesModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.VehiclesModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.VehiclesModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.VFXModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.VFXModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.VFXModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.VideoModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.VideoModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.VideoModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.VRModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.VRModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.VRModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.WindModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.WindModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.WindModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.XRModule">
<HintPath>..\ref\GamecraftPreview_Data\Managed\UnityEngine.XRModule.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.XRModule.dll</HintPath>
</Reference>
<Reference Include="IllusionInjector">
<HintPath>..\ref\GamecraftPreview_Data\Managed\IllusionInjector.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\IllusionInjector.dll</HintPath>
</Reference>
<Reference Include="IllusionPlugin">
<HintPath>..\ref\GamecraftPreview_Data\Managed\IllusionPlugin.dll</HintPath>
<HintPath>..\..\ref\GamecraftPreview_Data\Managed\IllusionPlugin.dll</HintPath>
</Reference>
</ItemGroup>
<!--End Dependencies-->
</Project>

View file

@ -1,24 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace GamecraftModdingAPI
{
public class GamecraftModdingAPIException : Exception
{
public GamecraftModdingAPIException()
{
}
public GamecraftModdingAPIException(string message) : base(message)
{
}
public GamecraftModdingAPIException(string message, Exception innerException) : base(message, innerException)
{
}
protected GamecraftModdingAPIException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}

View file

@ -1,146 +0,0 @@
using System;
using RobocraftX.Common;
using RobocraftX.Common.Input;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Input
{
public static class FakeInput
{
private static readonly FakeInputEngine inputEngine = new FakeInputEngine();
/// <summary>
/// Customize the player input.
/// </summary>
/// <param name="input">The custom input.</param>
/// <param name="playerID">The player. Omit this to use the local player.</param>
public static void CustomInput(LocalInputEntityStruct input, uint playerID = uint.MaxValue)
{
if (playerID == uint.MaxValue)
{
playerID = inputEngine.GetLocalPlayerID();
}
inputEngine.SendCustomInput(input, playerID);
}
public static LocalInputEntityStruct GetInput(uint playerID = uint.MaxValue)
{
if (playerID == uint.MaxValue)
{
playerID = inputEngine.GetLocalPlayerID();
}
return inputEngine.GetInput(playerID);
}
/// <summary>
/// Fake a GUI input.
/// Omit any parameter you do not want to affect.
/// Parameters that end with "?" don't do anything... yet.
/// </summary>
/// <param name="playerID">The player. Omit this to use the local player.</param>
/// <param name="hotbar">Select the hotbar slot by number.</param>
/// <param name="commandLine">Toggle the command line?</param>
/// <param name="escape">Open escape menu?</param>
/// <param name="enter">Page return?</param>
/// <param name="debug">Toggle debug display?</param>
/// <param name="next">Select next?</param>
/// <param name="previous">Select previous?</param>
/// <param name="tab">Tab?</param>
/// <param name="colour">Toggle to hotbar colour mode?</param>
/// <param name="hotbarPage">Select the hotbar page by number?</param>
/// <param name="quickSave">Quicksave?</param>
/// <param name="paste">Paste?</param>
public static void GuiInput(uint playerID = uint.MaxValue, int hotbar = -1, bool commandLine = false, bool escape = false, bool enter = false, bool debug = false, bool next = false, bool previous = false, bool tab = false, bool colour = false, int hotbarPage = -1, bool quickSave = false, bool paste = false)
{
if (playerID == uint.MaxValue)
{
playerID = inputEngine.GetLocalPlayerID();
}
ref LocalInputEntityStruct currentInput = ref inputEngine.GetInputRef(playerID);
//Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
// set inputs
switch(hotbar)
{
case 0: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_0; break;
case 1: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_1; break;
case 2: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_2; break;
case 3: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_3; break;
case 4: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_4; break;
case 5: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_5; break;
case 6: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_6; break;
case 7: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_7; break;
case 8: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_8; break;
case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_9; break;
default: break;
}
if (commandLine) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleCommandLine;
if (escape) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Escape;
if (enter) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Return;
if (debug) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleDebugDisplay;
if (next) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.SelectNext;
if (previous) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.SelectPrev;
if (tab) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Tab;
switch (hotbarPage)
{
case 1: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage1; break;
case 2: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage2; break;
case 3: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage3; break;
case 4: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage4; break;
case 5: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage5; break;
case 6: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage6; break;
case 7: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage7; break;
case 8: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage8; break;
case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage9; break;
case 10: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage10; break;
default: break;
}
if (quickSave) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.QuickSave;
if (paste) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.PasteSelection;
}
public static void ActionInput(uint playerID = uint.MaxValue, bool toggleMode = false, bool forward = false, bool backward = false, bool up = false, bool down = false, bool left = false, bool right = false, bool sprint = false, bool toggleFly = false, bool alt = false, bool primary = false, bool secondary = false, bool tertiary = false, bool primaryHeld = false, bool secondaryHeld = false, bool toggleUnitGrid = false, bool ctrl = false, bool toggleColourMode = false, bool scaleBlockUp = false, bool scaleBlockDown = false, bool rotateBlockClockwise = false, bool rotateBlockCounterclockwise = false, bool cutSelection = false, bool copySelection = false, bool deleteSelection = false)
{
if (playerID == uint.MaxValue)
{
playerID = inputEngine.GetLocalPlayerID();
}
ref LocalInputEntityStruct currentInput = ref inputEngine.GetInputRef(playerID);
//Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
// set inputs
if (toggleMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleTimeRunningMode;
if (forward) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Forward;
if (backward) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Backward;
if (up) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Up;
if (down) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Down;
if (left) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Left;
if (right) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Right;
if (sprint) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Sprint;
if (toggleFly) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SwitchFlyMode;
if (alt) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.AltAction;
if (primary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryAction;
if (secondary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SecondaryAction;
if (tertiary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.TertiaryAction;
if (primaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryActionHeld;
if (secondaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SecondaryActionHeld;
if (toggleUnitGrid) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleUnitGrid;
if (ctrl) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CtrlAction;
if (toggleColourMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleColourMode;
if (scaleBlockUp) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ScaleBlockUp;
if (scaleBlockDown) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ScaleBlockDown;
if (rotateBlockClockwise) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.RotateBlockClockwise;
if (rotateBlockCounterclockwise) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.RotateBlockAnticlockwise;
if (cutSelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CutSelection;
if (copySelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CopySelection;
if (deleteSelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.DeleteSelection;
}
public static void Init()
{
GameEngineManager.AddGameEngine(inputEngine);
MenuEngineManager.AddMenuEngine(inputEngine);
}
}
}

View file

@ -1,65 +0,0 @@
using System;
using RobocraftX.Common.Input;
using RobocraftX.Players;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;
namespace GamecraftModdingAPI.Input
{
public class FakeInputEngine : IApiEngine
{
public string Name { get; } = "GamecraftModdingAPIFakeInputEngine";
public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => false;
public bool IsReady = false;
public void Dispose()
{
IsReady = false;
}
public void Ready()
{
IsReady = true;
}
public bool SendCustomInput(LocalInputEntityStruct input, uint playerID, bool remote = false)
{
EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
if (entitiesDB.Exists<LocalInputEntityStruct>(egid))
{
ref LocalInputEntityStruct ies = ref entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
ies = input;
return true;
}
else return false;
}
public LocalInputEntityStruct GetInput(uint playerID, bool remote = false)
{
EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
if (entitiesDB.Exists<LocalInputEntityStruct>(egid))
{
return entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
}
else return default(LocalInputEntityStruct);
}
public ref LocalInputEntityStruct GetInputRef(uint playerID, bool remote = false)
{
EGID egid = new EGID(playerID, remote ? InputExclusiveGroups.RemotePlayers : InputExclusiveGroups.LocalPlayers);
return ref entitiesDB.QueryEntity<LocalInputEntityStruct>(egid);
}
public uint GetLocalPlayerID()
{
return LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB);
}
}
}

View file

@ -1,47 +0,0 @@
using System;
using RobocraftX.Common.Input;
using RobocraftX.Multiplayer.Input;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Utility;
using HarmonyLib;
namespace GamecraftModdingAPI.Inventory
{
public static class Hotbar
{
private static readonly HotbarEngine hotbarEngine = new HotbarEngine();
/// <summary>
/// Switch the block in the player's hand
/// </summary>
/// <param name="block">The block to switch to.</param>
/// <param name="playerID">The player. Omit this to use the local player.</param>
public static void EquipBlock(BlockIDs block, uint playerID = uint.MaxValue)
{
if (playerID == uint.MaxValue)
{
playerID = hotbarEngine.GetLocalPlayerID();
}
hotbarEngine.SelectBlock((int) block, playerID);
// cubeSelectedByPick = true will crash the game
// (this would be equivalent to mouse middle click pick block action)
// reason: the game expects a Dictionary entry for the tweaked stats
}
/// <summary>
/// Gets the block in the player's hand
/// </summary>
/// <returns>The equipped block.</returns>
public static BlockIDs GetEquippedBlock()
{
return HotbarSlotSelectionHandlerEnginePatch.EquippedPartID;
}
public static void Init()
{
GameEngineManager.AddGameEngine(hotbarEngine);
}
}
}

View file

@ -1,58 +0,0 @@
using System;
using RobocraftX.Character;
using RobocraftX.GUI.Hotbar;
using RobocraftX.Players;
using RobocraftX.Common;
using RobocraftX.Common.Input;
using RobocraftX.Common.Players;
using Svelto.ECS;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;
namespace GamecraftModdingAPI.Inventory
{
public class HotbarEngine : IApiEngine
{
public string Name { get; } = "GamecraftModdingAPIHotbarGameEngine";
public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => false;
public bool IsInGame = false;
public void Dispose()
{
IsInGame = false;
}
public void Ready()
{
IsInGame = true;
}
public bool SelectBlock(int block, uint playerID, bool cubeSelectedByPick = false)
{
var inputs = entitiesDB.QueryEntities<LocalInputEntityStruct>(InputExclusiveGroups.LocalPlayers);
if (inputs.count == 0) return false;
for (int i = 0; i < inputs.count; i++)
{
if (inputs[i].ID.entityID == playerID) {
inputs[i].cubeSelectedByPick = cubeSelectedByPick;
inputs[i].selectedCube = block;
return true;
}
}
// TODO: expose the rest of the input functionality
return false;
}
public uint GetLocalPlayerID()
{
return LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB);
}
}
}

View file

@ -1,32 +0,0 @@
using System;
using System.Reflection;
using RobocraftX.GUI;
using RobocraftX.GUI.Hotbar;
using Svelto.ECS;
using HarmonyLib;
using GamecraftModdingAPI.Blocks;
namespace GamecraftModdingAPI.Inventory
{
[HarmonyPatch]
public class HotbarSlotSelectionHandlerEnginePatch
{
private static int selectedBlockInt = 0;
public static BlockIDs EquippedPartID { get => (BlockIDs)selectedBlockInt; }
private static MethodInfo PatchedMethod { get; } = AccessTools.Method(AccessTools.TypeByName("RobocraftX.GUI.Hotbar.HotbarSlotSelectionHandlerEngine"), "ActivateSlotForCube", parameters: new Type[] { typeof(uint), typeof(int), typeof(ExclusiveGroupStruct) });
public static void Prefix(uint playerID, int selectedDBPartID, ExclusiveGroupStruct groupID)
{
selectedBlockInt = selectedDBPartID;
}
public static MethodBase TargetMethod(Harmony harmonyInstance)
{
return PatchedMethod;
}
}
}

View file

@ -1,103 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using HarmonyLib;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Events;
using GamecraftModdingAPI.Players;
using GamecraftModdingAPI.Tasks;
using uREPL;
namespace GamecraftModdingAPI
{
/// <summary>
/// The main class of the GamecraftModdingAPI.
/// Use this to initialize the API before calling it.
/// </summary>
public static class Main
{
private static Harmony harmony;
public static bool IsInitialized {
get { return harmony != null; }
}
private static int referenceCount = 0;
/// <summary>
/// Initializes the GamecraftModdingAPI.
/// Call this as soon as possible after Gamecraft starts up.
/// Ideally, this should be called from your main Plugin class's OnApplicationStart() method.
/// </summary>
public static void Init()
{
referenceCount++;
if (referenceCount > 1) { return; }
if (IsInitialized)
{
Logging.LogWarning("GamecraftModdingAPI.Main.Init() called but API is already initialized!");
return;
}
Logging.MetaDebugLog($"Patching Gamecraft");
var currentAssembly = Assembly.GetExecutingAssembly();
harmony = new Harmony(currentAssembly.GetName().Name);
harmony.PatchAll(currentAssembly);
// init utility
Logging.MetaDebugLog($"Initializing Utility");
Utility.GameState.Init();
Utility.VersionTracking.Init();
// create default event emitters
Logging.MetaDebugLog($"Initializing Events");
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.ApplicationInitialized, "GamecraftModdingAPIApplicationInitializedEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.Menu, "GamecraftModdingAPIMenuActivatedEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.MenuSwitchedTo, "GamecraftModdingAPIMenuSwitchedToEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.Game, "GamecraftModdingAPIGameActivatedEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameReloaded, "GamecraftModdingAPIGameReloadedEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameSwitchedTo, "GamecraftModdingAPIGameSwitchedToEventEmitter", false));
EventManager.AddEventEmitter(GameHostTransitionDeterministicGroupEnginePatch.buildEngine);
EventManager.AddEventEmitter(GameHostTransitionDeterministicGroupEnginePatch.simEngine);
// init block implementors
Logging.MetaDebugLog($"Initializing Blocks");
// init inventory
Inventory.Hotbar.Init();
// init input
Input.FakeInput.Init();
// init object-oriented classes
Player.Init();
Block.Init();
GameClient.Init();
AsyncUtils.Init();
GamecraftModdingAPI.App.Client.Init();
GamecraftModdingAPI.App.Game.Init();
Logging.MetaLog($"{currentAssembly.GetName().Name} v{currentAssembly.GetName().Version} initialized");
}
/// <summary>
/// Shuts down & cleans up the GamecraftModdingAPI.
/// Call this as late as possible before Gamecraft quits.
/// Ideally, this should be called from your main Plugin class's OnApplicationQuit() method.
/// </summary>
public static void Shutdown()
{
if (referenceCount > 0) { referenceCount--; }
if (referenceCount == 0)
{
if (!IsInitialized)
{
Logging.LogWarning("GamecraftModdingAPI.Main.Shutdown() called but API is not initialized!");
return;
}
Scheduler.Dispose();
var currentAssembly = Assembly.GetExecutingAssembly();
harmony.UnpatchAll(currentAssembly.GetName().Name);
harmony = null;
Logging.MetaLog($"{currentAssembly.GetName().Name} v{currentAssembly.GetName().Version} shutdown");
}
}
}
}

View file

@ -1,421 +0,0 @@
using System;
using Unity.Mathematics;
using RobocraftX.Common;
using RobocraftX.Common.Players;
using Svelto.ECS;
using GamecraftModdingAPI.Players;
using GamecraftModdingAPI.Blocks;
namespace GamecraftModdingAPI
{
/// <summary>
/// An in-game player character. Any Leo you see is a player.
/// </summary>
public class Player : IEquatable<Player>, IEquatable<EGID>
{
// static functionality
private static PlayerEngine playerEngine = new PlayerEngine();
/// <summary>
/// Checks if the specified player exists.
/// </summary>
/// <returns>Whether the player exists.</returns>
/// <param name="player">Player type.</param>
public static bool Exists(PlayerType player)
{
switch (player)
{
case PlayerType.Remote:
return playerEngine.GetRemotePlayer() != uint.MaxValue;
case PlayerType.Local:
return playerEngine.GetLocalPlayer() != uint.MaxValue;
}
return false;
}
/// <summary>
/// Checks if the specified player exists.
/// </summary>
/// <returns>Whether the player exists.</returns>
/// <param name="player">The player's unique identifier.</param>
public static bool Exists(uint player)
{
return playerEngine.ExistsById(player);
}
/// <summary>
/// The amount of Players in the current game.
/// </summary>
/// <returns>The count.</returns>
public static uint Count()
{
return (uint) playerEngine.GetAllPlayerCount();
}
/// <summary>
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Player"/> class.
/// </summary>
/// <param name="id">The player's unique identifier.</param>
public Player(uint id)
{
this.Id = id;
if (!Exists(id))
{
throw new PlayerNotFoundException($"No player with id {id} exists");
}
this.Type = playerEngine.GetLocalPlayer() == id ? PlayerType.Local : PlayerType.Remote;
}
/// <summary>
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Player"/> class.
/// </summary>
/// <param name="player">The player type. Chooses the first available player matching the criteria.</param>
public Player(PlayerType player)
{
switch (player)
{
case PlayerType.Local:
this.Id = playerEngine.GetLocalPlayer();
break;
case PlayerType.Remote:
this.Id = playerEngine.GetRemotePlayer();
break;
}
if (this.Id == uint.MaxValue)
{
throw new PlayerNotFoundException($"No player of {player} type exists");
}
this.Type = player;
}
// object fields & properties
/// <summary>
/// The player's type.
/// The player type is always relative to the current client, not the game host.
/// </summary>
/// <value>The enumerated player type.</value>
public PlayerType Type { get; }
/// <summary>
/// The player's unique identifier.
/// </summary>
/// <value>The identifier.</value>
public uint Id { get; }
/// <summary>
/// The player's current position.
/// </summary>
/// <value>The position.</value>
public float3 Position
{
get
{
return playerEngine.GetLocation(Id);
}
set
{
playerEngine.SetLocation(Id, value, false);
}
}
/// <summary>
/// The player's current rotation.
/// </summary>
/// <value>The rotation.</value>
public float3 Rotation
{
get
{
return playerEngine.GetRotation(Id);
}
set
{
playerEngine.SetRotation(Id, value);
}
}
/// <summary>
/// The player's current velocity.
/// </summary>
/// <value>The velocity.</value>
public float3 Velocity
{
get
{
return playerEngine.GetLinearVelocity(Id);
}
set
{
playerEngine.SetLinearVelocity(Id, value);
}
}
/// <summary>
/// The player's current angular velocity.
/// </summary>
/// <value>The angular velocity.</value>
public float3 AngularVelocity
{
get
{
return playerEngine.GetAngularVelocity(Id);
}
set
{
playerEngine.SetAngularVelocity(Id, value);
}
}
/// <summary>
/// The player's mass.
/// </summary>
/// <value>The mass.</value>
public float Mass
{
get
{
return 1f / playerEngine.GetMass(Id).InverseMass;
}
// FIXME: Setting mass doesn't do anything
/*set
{
playerEngine.SetInverseMass(Id, 1f / value);
}*/
}
private float _ping = -1f;
/// <summary>
/// The player's latest network ping time.
/// </summary>
/// <value>The ping (s).</value>
public float Ping
{
get
{
float? temp = playerEngine.GetLastPingTime(Id, Type);
if (temp.HasValue)
{
_ping = temp.Value;
}
return _ping;
}
}
/// <summary>
/// The player's initial health when entering Simulation (aka Time Running) mode.
/// </summary>
/// <value>The initial health.</value>
public float InitialHealth
{
get => playerEngine.GetInitialHealth(Id);
set
{
playerEngine.SetInitialHealth(Id, value);
}
}
/// <summary>
/// The player's current health in Simulation (aka Time Running) mode.
/// </summary>
/// <value>The current health.</value>
public float CurrentHealth
{
get => playerEngine.GetCurrentHealth(Id);
set
{
playerEngine.DamagePlayer(Id, CurrentHealth - value);
}
}
/// <summary>
/// Whether this <see cref="T:GamecraftModdingAPI.Player"/> is damageable.
/// </summary>
/// <value><c>true</c> if damageable; otherwise, <c>false</c>.</value>
public bool Damageable
{
get => playerEngine.GetDamageable(Id);
set
{
playerEngine.SetDamageable(Id, value);
}
}
/// <summary>
/// The player's lives when initially entering Simulation (aka Time Running) mode.
/// </summary>
/// <value>The initial lives.</value>
public uint InitialLives
{
get => playerEngine.GetInitialLives(Id);
set => playerEngine.SetInitialLives(Id, value);
}
/// <summary>
/// The player's current lives in Simulation (aka Time Running) mode.
/// </summary>
/// <value>The current lives.</value>
public uint CurrentLives
{
get => playerEngine.GetCurrentLives(Id);
set => playerEngine.SetCurrentLives(Id, value);
}
/// <summary>
/// Whether the Game Over screen is displayed for the player.
/// </summary>
/// <value><c>true</c> if game over; otherwise, <c>false</c>.</value>
public bool GameOver
{
get => playerEngine.GetGameOverScreen(Id);
}
/// <summary>
/// Whether the player is dead.
/// If <c>true</c>, hopefully it was quick.
/// </summary>
/// <value><c>true</c> if dead; otherwise, <c>false</c>.</value>
public bool Dead
{
get => playerEngine.IsDead(Id);
}
/// <summary>
/// The player's selected block ID in their hand.
/// </summary>
/// <value>The selected block.</value>
public BlockIDs SelectedBlock
{
get
{
return (BlockIDs)playerEngine.GetSelectedBlock(Id);
}
}
/// <summary>
/// The player's selected block color in their hand.
/// </summary>
/// <value>The selected block's color.</value>
public BlockColor SelectedColor
{
get
{
return new BlockColor(playerEngine.GetSelectedColor(Id));
}
}
/// <summary>
/// The player's selected block colour in their hand.
/// </summary>
/// <value>The selected block's colour.</value>
public BlockColor SelectedColour
{
get
{
return new BlockColor(playerEngine.GetSelectedColor(Id));
}
}
// object methods
/// <summary>
/// Teleport the player to the specified coordinates.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <param name="z">The z coordinate.</param>
/// <param name="relative">If set to <c>true</c> teleport relative to the player's current position.</param>
/// <param name="exitSeat">If set to <c>true</c> exit any seat the player is in.</param>
public void Teleport(float x, float y, float z, bool relative = true, bool exitSeat = true)
{
float3 location = new float3(x, y, z);
if (relative)
{
location += playerEngine.GetLocation(Id);
}
playerEngine.SetLocation(Id, location, exitSeat: exitSeat);
}
/// <summary>
/// Returns the block the player is currently looking at in build mode.
/// </summary>
/// <param name="maxDistance">The maximum distance from the player (default is the player's building reach)</param>
/// <returns>The block or null if not found</returns>
public Block GetBlockLookedAt(float maxDistance = -1f)
{
var egid = playerEngine.GetThingLookedAt(Id, maxDistance);
return egid.HasValue && egid.Value.groupID != CommonExclusiveGroups.SIMULATION_BODIES_GROUP
? new Block(egid.Value)
: null;
}
/// <summary>
/// Returns the rigid body the player is currently looking at during simulation.
/// </summary>
/// <param name="maxDistance">The maximum distance from the player (default is the player's building reach)</param>
/// <returns>The block or null if not found</returns>
public SimBody GetSimBodyLookedAt(float maxDistance = -1f)
{
var egid = playerEngine.GetThingLookedAt(Id, maxDistance);
return egid.HasValue && egid.Value.groupID == CommonExclusiveGroups.SIMULATION_BODIES_GROUP
? new SimBody(egid.Value)
: null;
}
/// <summary>
/// Returns the blocks that are in the player's current selection.
/// </summary>
/// <returns>An array of blocks or an empty array</returns>
public Block[] GetSelectedBlocks()
{
return playerEngine.GetSelectedBlocks(Id);
}
public bool Equals(Player other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Id == other.Id;
}
public bool Equals(EGID other)
{
return Id == other.entityID && other.groupID == (Type == PlayerType.Local
? PlayersExclusiveGroups.LocalPlayers
: PlayersExclusiveGroups.RemotePlayers);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Player) obj);
}
public override int GetHashCode()
{
return (int) Id;
}
// internal methods
internal static void Init()
{
Utility.GameEngineManager.AddGameEngine(playerEngine);
}
}
}

View file

@ -1,485 +0,0 @@
using System;
using System.Runtime.CompilerServices;
using RobocraftX.Character;
using RobocraftX.Character.Movement;
using RobocraftX.Common.Players;
using RobocraftX.Common.Input;
using RobocraftX.CR.MachineEditing.BoxSelect;
using RobocraftX.Physics;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Character.Camera;
using RobocraftX.Character.Factories;
using Gamecraft.CharacterVulnerability;
using Gamecraft.CharacterVulnerability.Entities;
using Svelto.ECS;
using Unity.Mathematics;
using Unity.Physics;
using UnityEngine;
using GamecraftModdingAPI.Engines;
namespace GamecraftModdingAPI.Players
{
internal class PlayerEngine : IApiEngine, IFactoryEngine
{
public string Name { get; } = "GamecraftModdingAPIPlayerGameEngine";
public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => false;
public IEntityFactory Factory { set; private get; }
private bool isReady = false;
public void Dispose()
{
isReady = false;
}
public void Ready()
{
isReady = true;
}
public uint GetLocalPlayer()
{
if (!isReady) return uint.MaxValue;
var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers);
if (localPlayers.count > 0)
{
return localPlayers[0].ID.entityID;
}
return uint.MaxValue;
}
public uint GetRemotePlayer()
{
if (!isReady) return uint.MaxValue;
var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers);
if (localPlayers.count > 0)
{
return localPlayers[0].ID.entityID;
}
return uint.MaxValue;
}
public long GetAllPlayerCount()
{
if (entitiesDB == null) return 0;
long count = 0;
foreach (ExclusiveGroupStruct eg in PlayersExclusiveGroups.AllPlayers)
{
count += entitiesDB.Count<PlayerIDStruct>(eg);
}
return count;
}
public long GetLocalPlayerCount()
{
if (entitiesDB == null) return 0;
return entitiesDB.Count<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers);
}
public long GetRemotePlayerCount()
{
if (entitiesDB == null) return 0;
return entitiesDB.Count<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers);
}
public bool ExistsById(uint playerId)
{
if (entitiesDB == null) return false;
return entitiesDB.Exists<PlayerIDStruct>(playerId, PlayersExclusiveGroups.LocalPlayers)
|| entitiesDB.Exists<PlayerIDStruct>(playerId, PlayersExclusiveGroups.RemotePlayers);
}
public float3 GetLocation(uint playerId)
{
if (entitiesDB == null) return float3.zero;
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
if (exists)
{
return rbes.position;
}
return float3.zero;
}
public bool SetLocation(uint playerId, float3 location, bool exitSeat = true)
{
if (entitiesDB == null) return false;
var characterGroups = CharacterExclusiveGroups.AllCharacters;
for (int i = 0; i < characterGroups.count; i++)
{
EGID egid = new EGID(playerId, characterGroups[i]);
if (entitiesDB.Exists<RigidBodyEntityStruct>(egid))
{
ref RigidBodyEntityStruct rbes = ref entitiesDB.QueryEntity<RigidBodyEntityStruct>(egid);
if (characterGroups[i] == CharacterExclusiveGroups.InPilotSeatGroup && exitSeat)
{
entitiesDB.QueryEntity<CharacterPilotSeatEntityStruct>(egid).instantExit = true;
entitiesDB.PublishEntityChange<CharacterPilotSeatEntityStruct>(egid);
}
rbes.position = location;
return true;
}
}
return false;
}
public float3 GetRotation(uint playerId)
{
if (entitiesDB == null) return float3.zero;
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
if (exists)
{
return ((Quaternion) rbes.rotation).eulerAngles;
}
return default(float3);
}
public bool SetRotation(uint playerId, float3 value)
{
if (entitiesDB == null) return false;
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
if (exists)
{
Quaternion q = rbes.rotation;
q.eulerAngles = value;
rbes.rotation = q;
return true;
}
return false;
}
public float3 GetLinearVelocity(uint playerId)
{
if (entitiesDB == null) return float3.zero;
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
if (exists)
{
return rbes.velocity;
}
return float3.zero;
}
public bool SetLinearVelocity(uint playerId, float3 value)
{
if (entitiesDB == null) return false;
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
if (exists)
{
rbes.velocity = value;
return true;
}
return false;
}
public float3 GetAngularVelocity(uint playerId)
{
if (entitiesDB == null) return float3.zero;
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
if (exists)
{
return rbes.angularVelocity;
}
return float3.zero;
}
public bool SetAngularVelocity(uint playerId, float3 value)
{
if (entitiesDB == null) return false;
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
if (exists)
{
rbes.angularVelocity = value;
return true;
}
return false;
}
public PhysicsMass GetMass(uint playerId)
{
if (entitiesDB == null) return default(PhysicsMass);
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
if (exists)
{
return rbes.physicsMass;
}
return default(PhysicsMass);
}
public bool SetInverseMass(uint playerId, float inverseMass)
{
if (entitiesDB == null) return false;
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
if (exists)
{
rbes.physicsMass.InverseInertia = inverseMass;
return true;
}
return false;
}
public float? GetLastPingTime(uint playerId, PlayerType type)
{
if (entitiesDB == null) return null;
EGID egid = new EGID(playerId, PlayerGroupFromEnum(type));
if (entitiesDB.Exists<PlayerNetworkStatsEntityStruct>(egid))
{
return entitiesDB.QueryEntity<PlayerNetworkStatsEntityStruct>(egid).lastPingTimeSinceLevelLoad;
}
return null;
}
public float GetInitialHealth(uint playerId)
{
if (entitiesDB == null) return 0;
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
if (exists)
{
return c.initialHealth;
}
return -1f;
}
public bool SetInitialHealth(uint playerId, float val)
{
if (entitiesDB == null) return false;
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
if (exists)
{
c.initialHealth = val;
return true;
}
return false;
}
public float GetCurrentHealth(uint playerId)
{
if (entitiesDB == null) return 0;
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
if (exists)
{
return c.currentHealth;
}
return -1f;
}
public bool SetCurrentHealth(uint playerId, float val)
{
if (entitiesDB == null) return false;
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
if (exists)
{
c.currentHealth = val;
return true;
}
return false;
}
public bool DamagePlayer(uint playerId, float amount)
{
if (entitiesDB == null) return false;
Factory.BuildEntity<DamageEntityDescriptor>(
new EGID(CharacterVulnerabilityExclusiveGroups.NextDamageEntityId, CharacterVulnerabilityExclusiveGroups.CharacterDamageExclusiveGroup)
).Init(new DamageEntityStruct
{
damage = amount,
targetPlayerEntityId = playerId,
});
return true;
}
public bool GetDamageable(uint playerId)
{
if (entitiesDB == null) return false;
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
if (exists)
{
return c.canTakeDamageStat;
}
return false;
}
public bool SetDamageable(uint playerId, bool val)
{
if (entitiesDB == null) return false;
ref var ches = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
if (exists)
{
ches.canTakeDamage = val;
ches.canTakeDamage = val;
return true;
}
return false;
}
public uint GetInitialLives(uint playerId)
{
if (entitiesDB == null) return 0;
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists);
if (exists)
{
return c.initialLives;
}
return uint.MaxValue;
}
public bool SetInitialLives(uint playerId, uint val)
{
if (entitiesDB == null) return false;
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists);
if (exists)
{
c.initialLives = val;
return true;
}
return false;
}
public uint GetCurrentLives(uint playerId)
{
if (entitiesDB == null) return 0;
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists);
if (exists)
{
return c.currentLives;
}
return uint.MaxValue;
}
public bool SetCurrentLives(uint playerId, uint val)
{
if (entitiesDB == null) return false;
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists);
if (exists)
{
c.currentLives = val;
return true;
}
return false;
}
public bool GetGameOverScreen(uint playerId)
{
if (entitiesDB == null) return false;
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists);
if (exists)
{
return c.gameOverScreen;
}
return false;
}
public bool IsDead(uint playerId)
{
if (entitiesDB == null) return true;
return entitiesDB.Exists<RigidBodyEntityStruct>(playerId, CharacterExclusiveGroups.DeadCharacters);
}
public int GetSelectedBlock(uint playerId)
{
if (entitiesDB == null) return 0;
ref var c = ref GetCharacterStruct<EquippedPartStruct>(playerId, out bool exists);
if (exists)
{
return c.SelectedDBPartID;
}
return ushort.MaxValue;
}
public byte GetSelectedColor(uint playerId)
{
if (entitiesDB == null) return 0;
ref var c = ref GetCharacterStruct<EquippedColourStruct>(playerId, out bool exists);
if (exists)
{
return c.indexInPalette;
}
return 255;
}
// reusable methods
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private ExclusiveGroup PlayerGroupFromEnum(PlayerType type)
{
return type == PlayerType.Local ? PlayersExclusiveGroups.LocalPlayers : PlayersExclusiveGroups.RemotePlayers;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T GetCharacterStruct<T>(uint playerId, out bool exists) where T : unmanaged, IEntityComponent
{
var characterGroups = CharacterExclusiveGroups.AllCharacters;
for (int i = 0; i < characterGroups.count; i++)
{
EGID egid = new EGID(playerId, characterGroups[i]);
if (entitiesDB.Exists<T>(egid))
{
exists = true;
return ref entitiesDB.QueryEntity<T>(egid);
}
}
exists = false;
T[] arr = new T[1];
return ref arr[0]; //Return default value
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool GetPlayerStruct<T>(uint playerId, out T s) where T : unmanaged, IEntityComponent
{
var playerGroups = PlayersExclusiveGroups.AllPlayers;
for (int i = 0; i < playerGroups.count; i++)
{
EGID egid = new EGID(playerId, playerGroups[i]);
if (entitiesDB.Exists<T>(egid))
{
s = entitiesDB.QueryEntity<T>(egid);
return true;
}
}
s = default;
return false;
}
public EGID? GetThingLookedAt(uint playerId, float maxDistance = -1f)
{
if (!entitiesDB.TryQueryMappedEntities<CharacterCameraRayCastEntityStruct>(
CameraExclusiveGroups.CameraGroup, out var mapper))
return null;
mapper.TryGetEntity(playerId, out CharacterCameraRayCastEntityStruct rayCast);
float distance = maxDistance < 0
? GhostBlockUtils.GetBuildInteractionDistance(entitiesDB, rayCast,
GhostBlockUtils.GhostCastMethod.GhostCastProportionalToBlockSize)
: maxDistance;
if (rayCast.hit && rayCast.distance <= distance)
return rayCast.hitEgid;
return null;
}
public unsafe Block[] GetSelectedBlocks(uint playerid)
{
if (!entitiesDB.Exists<BoxSelectStateEntityStruct>(playerid,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup))
return new Block[0];
var state = entitiesDB.QueryEntity<BoxSelectStateEntityStruct>(playerid,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup);
var blocks = entitiesDB.QueryEntity<SelectedBlocksStruct>(playerid,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup);
if (!state.active) return new Block[0];
var pointer = (EGID*) blocks.selectedBlocks.ToPointer();
var ret = new Block[blocks.count];
for (int j = 0; j < blocks.count; j++)
{
var egid = pointer[j];
ret[j] = new Block(egid);
}
return ret;
}
}
}

View file

@ -1,42 +0,0 @@
using System;
using Unity.Mathematics;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Tests;
namespace GamecraftModdingAPI.Players
{
#if TEST
/// <summary>
/// Player test cases. Not accessible in release versions.
/// </summary>
[APITestClass]
public static class PlayerTests
{
[APITestCase(TestType.EditMode)]
public static void ExistsTest()
{
if (!Assert.Equal(Player.Exists(PlayerType.Local), true, "Local player does not exist.", "Local player detected.")) return;
Assert.Equal(Player.Count(), 1u, "Player.Count() is not one, possibly because it failed silently.", "Player count is one for single player game.");
}
[APITestCase(TestType.EditMode)]
public static void PositionTest()
{
Player p = new Player(PlayerType.Local);
if (!Assert.Errorless(() => { p.Teleport(0, 0, 0, relative: false); }, "Player.Teleport(origin) errored: ", "Player teleported to origin successfully.")) return;
if (!Assert.CloseTo(p.Position, float3.zero, "Player is not close to origin despite being teleported there.", "Player.Position is at origin.")) return;
if (!Assert.Errorless(() => { p.Position = float3.zero + 1; }, "Player.Position = origin+1 errored: ", "Player moved to origin+1.")) return;
Assert.CloseTo(p.Position, float3.zero + 1, "Player is not close to origin+1 despite being teleported there.", "Player.Position is at origin+1.");
}
[APITestCase(TestType.Menu)]
public static void InvalidStateTest()
{
if (!Assert.Errorless(() => { Player.Count(); }, "Player.Count() errored in menu.", "Player.Count() succeeded in menu.")) return;
Assert.Equal(Player.Count(), 0u, "Player.Count() is not zero in menu.", "Player count is zero in menu as expected.");
}
}
#endif
}

View file

@ -1,368 +0,0 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using HarmonyLib;
using IllusionInjector;
// test
using Svelto.ECS;
using RobocraftX.Blocks;
using RobocraftX.Common;
using RobocraftX.SimulationModeState;
using RobocraftX.FrontEnd;
using Unity.Mathematics;
using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Events;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Players;
namespace GamecraftModdingAPI.Tests
{
// unused by design
/// <summary>
/// Modding API implemented as a standalone IPA Plugin.
/// Ideally, GamecraftModdingAPI should be loaded by another mod; not itself
/// </summary>
public class GamecraftModdingAPIPluginTest
#if DEBUG
: IllusionPlugin.IEnhancedPlugin
#endif
{
private static Harmony harmony { get; set; }
public string[] Filter { get; } = new string[] { "Gamecraft", "GamecraftPreview" };
public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
public string HarmonyID { get; } = "org.git.exmods.modtainers.gamecraftmoddingapi";
public void OnApplicationQuit()
{
GamecraftModdingAPI.Main.Shutdown();
}
public void OnApplicationStart()
{
FileLog.Reset();
Harmony.DEBUG = true;
GamecraftModdingAPI.Main.Init();
Logging.MetaDebugLog($"Version group id {(uint)ApiExclusiveGroups.versionGroup}");
// in case Steam is not installed/running
// this will crash the game slightly later during startup
//SteamInitPatch.ForcePassSteamCheck = true;
// in case running in a VM
//MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true;
// disable some Gamecraft analytics
//AnalyticsDisablerPatch.DisableAnalytics = true;
// disable background music
Logging.MetaDebugLog("Audio Mixers: " + string.Join(",", AudioTools.GetMixers()));
//AudioTools.SetVolume(0.0f, "Music"); // The game now sets this from settings again after this is called :(
//Utility.VersionTracking.Enable();//(very) unstable
// debug/test handlers
HandlerBuilder.Builder()
.Name("appinit API debug")
.Handle(EventType.ApplicationInitialized)
.OnActivation(() => { Logging.Log("App Inited event!"); })
.Build();
HandlerBuilder.Builder("menuact API debug")
.Handle(EventType.Menu)
.OnActivation(() => { Logging.Log("Menu Activated event!"); })
.OnDestruction(() => { Logging.Log("Menu Destroyed event!"); })
.Build();
HandlerBuilder.Builder("menuswitch API debug")
.Handle(EventType.MenuSwitchedTo)
.OnActivation(() => { Logging.Log("Menu Switched To event!"); })
.Build();
HandlerBuilder.Builder("gameact API debug")
.Handle(EventType.Menu)
.OnActivation(() => { Logging.Log("Game Activated event!"); })
.OnDestruction(() => { Logging.Log("Game Destroyed event!"); })
.Build();
HandlerBuilder.Builder("gamerel API debug")
.Handle(EventType.GameReloaded)
.OnActivation(() => { Logging.Log("Game Reloaded event!"); })
.Build();
HandlerBuilder.Builder("gameswitch API debug")
.Handle(EventType.GameSwitchedTo)
.OnActivation(() => { Logging.Log("Game Switched To event!"); })
.Build();
HandlerBuilder.Builder("simulationswitch API debug")
.Handle(EventType.SimulationSwitchedTo)
.OnActivation(() => { Logging.Log("Game Mode Simulation Switched To event!"); })
.Build();
HandlerBuilder.Builder("buildswitch API debug")
.Handle(EventType.BuildSwitchedTo)
.OnActivation(() => { Logging.Log("Game Mode Build Switched To event!"); })
.Build();
HandlerBuilder.Builder("menu activated API error thrower test")
.Handle(EventType.Menu)
.OnActivation(() => { throw new Exception("Event Handler always throws an exception!"); })
.Build();
/*HandlerBuilder.Builder("enter game from menu test")
.Handle(EventType.Menu)
.OnActivation(() =>
{
Tasks.Scheduler.Schedule(new Tasks.Repeatable(enterGame, shouldRetry, 0.2f));
})
.Build();*/
// debug/test commands
if (Dependency.Hell("ExtraCommands"))
{
CommandBuilder.Builder()
.Name("Exit")
.Description("Close Gamecraft immediately, without any prompts")
.Action(() => { UnityEngine.Application.Quit(); })
.Build();
CommandBuilder.Builder()
.Name("SetFOV")
.Description("Set the player camera's field of view")
.Action((float d) => { UnityEngine.Camera.main.fieldOfView = d; })
.Build();
CommandBuilder.Builder()
.Name("MoveLastBlock")
.Description("Move the most-recently-placed block, and any connected blocks by the given offset")
.Action((float x, float y, float z) =>
{
if (GameState.IsBuildMode())
foreach (var block in Block.GetLastPlacedBlock().GetConnectedCubes())
block.Position += new Unity.Mathematics.float3(x, y, z);
else
GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
}).Build();
CommandBuilder.Builder()
.Name("PlaceAluminium")
.Description("Place a block of aluminium at the given coordinates")
.Action((float x, float y, float z) =>
{
var block = Block.PlaceNew(BlockIDs.AluminiumCube, new float3(x, y, z));
Logging.CommandLog("Block placed with type: " + block.Type);
})
.Build();
CommandBuilder.Builder()
.Name("PlaceAluminiumLots")
.Description("Place a lot of blocks of aluminium at the given coordinates")
.Action((float x, float y, float z) =>
{
Logging.CommandLog("Starting...");
var sw = Stopwatch.StartNew();
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
Block.PlaceNew(BlockIDs.AluminiumCube, new float3(x + i, y, z + j));
//Block.Sync();
sw.Stop();
Logging.CommandLog("Finished in " + sw.ElapsedMilliseconds + "ms");
})
.Build();
//With Sync(): 1135ms
//Without Sync(): 134ms
//Async: 348 794ms, doesn't freeze game
//Without Sync() but wait for submission: 530ms
//With Sync() at the end: 380ms
Block b = null;
CommandBuilder.Builder("moveBlockInSim", "Run in build mode first while looking at a block, then in sim to move it up")
.Action(() =>
{
if (b == null)
{
b = new Player(PlayerType.Local).GetBlockLookedAt();
Logging.CommandLog("Block saved: " + b);
}
else
Logging.CommandLog("Block moved to: " + (b.GetSimBody().Position += new float3(0, 2, 0)));
}).Build();
CommandBuilder.Builder("Error", "Throw an error to make sure SimpleCustomCommandEngine's wrapper catches it.")
.Action(() => { throw new Exception("Error Command always throws an error"); })
.Build();
CommandBuilder.Builder("ColorBlock",
"Change color of the block looked at if there's any.")
.Action<string>(str =>
{
if (!Enum.TryParse(str, out BlockColors color))
{
Logging.CommandLog("Color " + str + " not found! Interpreting as 4 color values.");
var s = str.Split(' ');
new Player(PlayerType.Local).GetBlockLookedAt().CustomColor = new float4(float.Parse(s[0]),
float.Parse(s[1]), float.Parse(s[2]), float.Parse(s[3]));
return;
}
new Player(PlayerType.Local).GetBlockLookedAt().Color =
new BlockColor { Color = color };
Logging.CommandLog("Colored block to " + color);
}).Build();
CommandBuilder.Builder("GetBlockByID", "Gets a block based on its object identifier and teleports it up.")
.Action<char>(ch =>
{
foreach (var body in SimBody.GetFromObjectID(ch))
{
Logging.CommandLog("SimBody: " + body);
body.Position += new float3(0, 10, 0);
foreach (var bodyConnectedBody in body.GetConnectedBodies())
{
Logging.CommandLog("Moving " + bodyConnectedBody);
bodyConnectedBody.Position += new float3(0, 10, 0);
}
}
}).Build();
GameClient.SetDebugInfo("InstalledMods", InstalledMods);
Block.Placed += (sender, args) =>
Logging.MetaDebugLog("Placed block " + args.Type + " with ID " + args.ID);
Block.Removed += (sender, args) =>
Logging.MetaDebugLog("Removed block " + args.Type + " with ID " + args.ID);
/*
CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
"SetFOV", "Set the player camera's field of view"));
CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
(x, y, z) => {
bool success = GamecraftModdingAPI.Blocks.Movement.MoveConnectedBlocks(
GamecraftModdingAPI.Blocks.BlockIdentifiers.LatestBlockID,
new Unity.Mathematics.float3(x, y, z));
if (!success)
{
GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
}
}, "MoveLastBlock", "Move the most-recently-placed block, and any connected blocks by the given offset"));
CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
(x, y, z) => { Blocks.Placement.PlaceBlock(Blocks.BlockIDs.AluminiumCube, new Unity.Mathematics.float3(x, y, z)); },
"PlaceAluminium", "Place a block of aluminium at the given coordinates"));
System.Random random = new System.Random(); // for command below
CommandManager.AddCommand(new SimpleCustomCommandEngine(
() => {
if (!GameState.IsSimulationMode())
{
Logging.CommandLogError("You must be in simulation mode for this to work!");
return;
}
Tasks.Repeatable task = new Tasks.Repeatable(() => {
uint count = 0;
EGID[] eBlocks = Blocks.Signals.GetElectricBlocks();
for (uint i = 0u; i < eBlocks.Length; i++)
{
uint[] ids = Blocks.Signals.GetSignalIDs(eBlocks[i]);
for (uint j = 0u; j < ids.Length; j++)
{
Blocks.Signals.SetSignalByID(ids[j], (float)random.NextDouble());
count++;
}
}
Logging.MetaDebugLog($"Did the thing on {count} inputs");
},
() => { return GameState.IsSimulationMode(); });
Tasks.Scheduler.Schedule(task);
}, "RandomizeSignalsInputs", "Do the thing"));
*/
}
// dependency test
if (Dependency.Hell("GamecraftScripting", new Version("0.0.1.0")))
{
Logging.LogWarning("You're in GamecraftScripting dependency hell");
}
else
{
Logging.Log("Compatible GamecraftScripting detected");
}
#if TEST
TestRoot.RunTests();
#endif
}
private string modsString;
private string InstalledMods()
{
if (modsString != null) return modsString;
StringBuilder sb = new StringBuilder("Installed mods:");
foreach (var plugin in PluginManager.Plugins)
sb.Append("\n" + plugin.Name + " - " + plugin.Version);
return modsString = sb.ToString();
}
private bool retry = true;
private bool shouldRetry()
{
return retry;
}
private void enterGame()
{
App.Client app = new App.Client();
App.Game[] myGames = app.MyGames;
Logging.MetaDebugLog($"MyGames count {myGames.Length}");
if (myGames.Length != 0)
{
Logging.MetaDebugLog($"MyGames[0] EGID {myGames[0].EGID}");
retry = false;
try
{
//myGames[0].Description = "test msg pls ignore"; // make sure game exists first
Logging.MetaDebugLog($"Entering game {myGames[0].Name}");
myGames[0].EnterGame();
}
catch (Exception e)
{
Logging.MetaDebugLog($"Failed to enter game; exception: {e}");
retry = true;
}
}
else
{
Logging.MetaDebugLog("MyGames not populated yet :(");
}
}
public void OnFixedUpdate() { }
public void OnLateUpdate() { }
public void OnLevelWasInitialized(int level) { }
public void OnLevelWasLoaded(int level) { }
public void OnUpdate() { }
[HarmonyPatch]
public class MinimumSpecsPatch
{
public static bool Prefix()
{
return false;
}
public static MethodInfo TargetMethod()
{
return ((Action) MinimumSpecsCheck.CheckRequirementsMet).Method;
}
}
}
}

View file

@ -1,35 +0,0 @@
using System.Threading.Tasks;
using Svelto.ECS;
namespace GamecraftModdingAPI.Utility
{
public static class AsyncUtils
{
private static AsyncUtilsEngine gameEngine = new AsyncUtilsEngine();
/// <summary>
/// Waits for entity submission asynchronously.
/// Use after placing a block or otherwise creating things in the game to access their properties.
/// </summary>
public static async Task WaitForSubmission()
{
await gameEngine.WaitForSubmission();
}
public static async Task WaitForNextFrame()
{
await gameEngine.WaitForNextFrame();
}
public static void Setup(EnginesRoot enginesRoot)
{
gameEngine.Setup(enginesRoot.GenerateEntityFunctions(), enginesRoot.GenerateEntityFactory());
}
public static void Init()
{
GameEngineManager.AddGameEngine(gameEngine);
}
}
}

View file

@ -1,63 +0,0 @@
using System.Collections;
using System.Threading.Tasks;
using RobocraftX.Schedulers;
using Svelto.ECS;
using Svelto.Tasks.ExtraLean;
using GamecraftModdingAPI.Engines;
namespace GamecraftModdingAPI.Utility
{
public class AsyncUtilsEngine : IApiEngine
{
private IEntityFunctions _efu;
private IEntityFactory _efa;
private IEnumerator WaitForSubmissionInternal(IEntityFunctions efu, IEntityFactory efa,
EntitiesDB entitiesDB, TaskCompletionSource<object> task)
{
var waitEnumerator = new WaitForSubmissionEnumerator(efu, efa, entitiesDB);
while (waitEnumerator.MoveNext())
yield return null;
task.SetResult(null);
}
private IEnumerator WaitForNextFrameInternal(TaskCompletionSource<object> task)
{
yield return null;
task.SetResult(null);
}
public Task WaitForSubmission()
{
var task = new TaskCompletionSource<object>();
WaitForSubmissionInternal(_efu, _efa, entitiesDB, task).RunOn(ExtraLean.EveryFrameStepRunner_TimeStopped);
return task.Task;
}
public Task WaitForNextFrame()
{
var task = new TaskCompletionSource<object>();
WaitForNextFrameInternal(task).RunOn(ExtraLean.EveryFrameStepRunner_TimeStopped);
return task.Task;
}
public void Setup(IEntityFunctions efu, IEntityFactory efa)
{
_efu = efu;
_efa = efa;
}
public void Ready()
{
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
}
public string Name { get; } = "GamecraftModdingAPIAsyncUtilsGameEngine";
public bool isRemovable { get; } = false;
}
}

View file

@ -1,25 +0,0 @@
using System;
using RobocraftX.StateSync;
using Svelto.ECS;
using HarmonyLib;
namespace GamecraftModdingAPI.Utility
{
[HarmonyPatch(typeof(DeterministicStepCompositionRoot), "ResetWorld")]
public static class DeterministicStepCompositionRootPatch
{
private static SimpleEntitiesSubmissionScheduler engineRootScheduler;
public static void Postfix(SimpleEntitiesSubmissionScheduler scheduler)
{
engineRootScheduler = scheduler;
}
internal static void SubmitEntitiesNow()
{
if (engineRootScheduler != null)
engineRootScheduler.SubmitEntities();
}
}
}

View file

@ -1,29 +0,0 @@
using System;
using GamecraftModdingAPI.Events;
namespace GamecraftModdingAPI.Utility
{
public static class ExceptionUtil
{
/// <summary>
/// Invokes an event in a try-catch block to avoid propagating exceptions.
/// </summary>
/// <param name="handler">The event to emit, can be null</param>
/// <param name="sender">Event sender</param>
/// <param name="args">Event arguments</param>
/// <typeparam name="T">Type of the event arguments</typeparam>
public static void InvokeEvent<T>(EventHandler<T> handler, object sender, T args)
{
try
{
handler?.Invoke(sender, args);
}
catch (Exception e)
{
EventRuntimeException wrappedException =
new EventRuntimeException($"EventHandler with arg type {typeof(T).Name} threw an exception", e);
Logging.LogWarning(wrappedException.ToString());
}
}
}
}

View file

@ -1,30 +0,0 @@
using System;
using GamecraftModdingAPI.Blocks;
namespace GamecraftModdingAPI.Utility
{
public static class GameClient
{
private static DebugInterfaceEngine _engine = new DebugInterfaceEngine();
/// <summary>
/// Saves the extra information to be displayed on the debug view.
/// The provided getter function is called each time the view updates so make sure it returns quickly.
/// </summary>
/// <param name="id">A global ID for the custom information</param>
/// <param name="contentGetter">A function that returns the current information</param>
public static void SetDebugInfo(string id, Func<string> contentGetter) => _engine.SetInfo(id, contentGetter);
/// <summary>
/// Removes an information provided by a plugin.
/// </summary>
/// <param name="id">The ID of the custom information</param>
/// <returns></returns>
public static bool RemoveDebugInfo(string id) => _engine.RemoveInfo(id);
public static void Init()
{
GameEngineManager.AddGameEngine(_engine);
}
}
}

View file

@ -1,112 +0,0 @@
using System;
using System.Reflection;
using RobocraftX.Common;
using Svelto.ECS;
using Svelto.ECS.Serialization;
using GamecraftModdingAPI.Persistence;
using GamecraftModdingAPI.Events;
namespace GamecraftModdingAPI.Utility
{
/// <summary>
/// Tracks the API version the current game was built for.
/// For compatibility reasons, this must be enabled before it will work.
/// </summary>
public static class VersionTracking
{
private static readonly VersionTrackingEngine versionEngine = new VersionTrackingEngine();
private static bool isEnabled = false;
/// <summary>
/// Gets the API version saved in the current game.
/// </summary>
/// <returns>The version.</returns>
public static uint GetVersion()
{
if (!isEnabled) return 0u;
return versionEngine.GetGameVersion();
}
/// <summary>
/// Enable API version tracking.
/// </summary>
public static void Enable()
{
if (!SerializerManager.ExistsSerializer(typeof(ModVersionStruct).FullName))
{
SerializerManager.AddSerializer<ModVersionDescriptor>(new SimpleEntitySerializer<ModVersionDescriptor>(
(_) => { return new EGID[1] { new EGID(0u, ApiExclusiveGroups.versionGroup) }; }
));
}
EventManager.AddEventEmitter(versionEngine);
isEnabled = true;
}
/// <summary>
/// Disable API version tracking.
/// </summary>
public static void Disable()
{
EventManager.AddEventEmitter(versionEngine);
isEnabled = false;
}
public static void Init() { }
}
internal class VersionTrackingEngine : IEventEmitterEngine
{
public string Name { get; } = "GamecraftModdingAPIVersionTrackingGameEngine";
public EntitiesDB entitiesDB { set; private get; }
public int type => -1;
public bool isRemovable => false;
public IEntityFactory Factory { set; private get; }
public void Dispose() { }
public void Ready()
{
EGID egid = new EGID(0u, ApiExclusiveGroups.versionGroup);
if (!entitiesDB.Exists<ModVersionStruct>(egid))
{
Version currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
int v = (currentVersion.Major * 1000) + (currentVersion.Minor);
Factory.BuildEntity<ModVersionDescriptor>(egid).Init<ModVersionStruct>(new ModVersionStruct
{
version = (uint)v
});
}
}
public uint GetGameVersion()
{
return entitiesDB.QueryUniqueEntity<ModVersionStruct>(ApiExclusiveGroups.versionGroup).version;
}
public void Emit() { }
}
public struct ModVersionStruct : IEntityComponent
{
public uint version;
}
public class ModVersionDescriptor: SerializableEntityDescriptor<ModVersionDescriptor._ModVersionDescriptor>
{
[HashName("GamecraftModdingAPIVersionV0")]
public class _ModVersionDescriptor : IEntityDescriptor
{
public IComponentBuilder[] componentsToBuild { get; } = new IComponentBuilder[]{
new SerializableComponentBuilder<SerializationType, ModVersionStruct>(((int)SerializationType.Network, new DefaultSerializer<ModVersionStruct>()), ((int)SerializationType.Storage, new DefaultSerializer<ModVersionStruct>())),
};
}
}
}

View file

@ -1,24 +1,31 @@
# GamecraftModdingAPI
# TechbloxModdingAPI
Unofficial Gamecraft modding API for interfacing Gamecraft from mods.
Unofficial Techblox modding API for interfacing Techblox from mods.
The GamecraftModdingAPI aims to simplify the mods in two ways:
The TechbloxModdingAPI aims to simplify the mods in two ways:
- *Ease-of-Use* The API provides convenient ways to do common tasks such as moving blocks and adding commands.
All of the Harmony patching is done for you, so you can focus on writing your mod instead of reading swathes of undocumented code.
- *Stability* The API aims to be reliable and consistent between versions.
This means your code won't break when the GamecraftModdingAPI or Gamecraft updates.
This means your code won't break when the TechbloxModdingAPI or Techblox updates.
For more info, please check out the [official documentation](https://mod.exmods.org).
For more support, join the ExMods [Discord](https://discord.gg/xjnFxQV).
For more support, join the ExMods [Discord](https://discord.exmods.org).
## Installation
[Please follow the official mod installation guide](https://www.exmods.org/guides/install.html)
[Please follow the official mod installation guide](https://www.exmods.org/guides/install.html) or use GCMM.
## Development
To get started, create a symbolic link called `ref` in the root of the project, or one folder higher, linking to the Techblox install folder.
This will allow your IDE to resolve references to Techblox files for building and IDE tools.
TechbloxModdingAPI version numbers follow the [Semantic Versioning guidelines](https://semver.org/).
## External Libraries
GamecraftModdingAPI includes [Harmony](https://github.com/pardeike/Harmony) to modify the behaviour of existing Gamecraft code.
TechbloxModdingAPI includes [Harmony](https://github.com/pardeike/Harmony) to modify the behaviour of existing Techblox code.
# Disclaimer
This API is an unofficial modification of Gamecraft software, and is not endorsed or supported by FreeJam or Gamecraft.
The GamecraftModdingAPI developer(s) claim no rights on the Gamecraft code referenced within this project.
This API is an unofficial modification of Techblox software, and is not endorsed or supported by FreeJam or Techblox.
The TechbloxModdingAPI developer(s) claim no rights on the Techblox code referenced within this project.
All code contained in this project is licensed under the [GNU Public License v3](https://git.exmods.org/modtainers/TechbloxModdingAPI/src/branch/master/LICENSE).

View file

@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29411.108
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GamecraftModdingAPI", "GamecraftModdingAPI\GamecraftModdingAPI.csproj", "{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechbloxModdingAPI", "TechbloxModdingAPI\TechbloxModdingAPI.csproj", "{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeGenerator", "CodeGenerator\CodeGenerator.csproj", "{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -18,6 +20,12 @@ Global
{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Release|Any CPU.Build.0 = Release|Any CPU
{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Test|Any CPU.ActiveCfg = Test|Any CPU
{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Test|Any CPU.Build.0 = Test|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Release|Any CPU.Build.0 = Release|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Test|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using HarmonyLib;
using Svelto.Tasks;
namespace TechbloxModdingAPI.App
{
public static class AntiAntiCheatPatch
{
private delegate bool AntiAnticheatDelegate(ref object __result);
private delegate bool AntiAnticheatDelegateBool(ref bool __result);
private delegate bool AntiAnticheatDelegateTask(ref IEnumerator<TaskContract> __result);
public static void Init(Harmony harmony)
{
var type = AccessTools.TypeByName("Techblox.Services.Eos.Anticheat.Client.Services.AnticheatClientService");
harmony.Patch(type.GetConstructors()[0], new HarmonyMethod(((Func<bool>) AntiAntiCheat).Method));
harmony.Patch(AccessTools.Method(type, "Shutdown"), new HarmonyMethod(((Func<bool>) AntiAntiCheat).Method));
harmony.Patch(AccessTools.Method(type, "StartProtectedSession"), new HarmonyMethod(((AntiAnticheatDelegate) AntiAntiCheat).Method));
harmony.Patch(AccessTools.Method(type, "StopProtectedSession"), new HarmonyMethod(((AntiAnticheatDelegateBool) AntiAntiCheat).Method));
harmony.Patch(AccessTools.Method("Techblox.Services.Eos.Anticheat.Client.EosGetPendingMessagesToSendServiceRequest:Execute"), new HarmonyMethod(((AntiAnticheatDelegateTask)AntiAntiCheatTask).Method));
harmony.Patch(AccessTools.Method("Techblox.Anticheat.Client.Engines.ShowFeedbackDialogEngine:PollAnticheatStatus"), new HarmonyMethod(((AntiAnticheatDelegateTask)AntiAntiCheatTask).Method));
}
private static bool AntiAntiCheat() => false;
private static bool AntiAntiCheat(ref object __result)
{
var targetType =
AccessTools.TypeByName("Techblox.Services.Eos.Anticheat.Client.Services.StartProtectedSessionResult");
var target = Activator.CreateInstance(targetType);
targetType.GetField("Success").SetValue(target, true);
__result = target;
return false;
}
private static bool AntiAntiCheat(ref bool __result)
{
__result = true;
return false;
}
private static bool AntiAntiCheatTask(ref IEnumerator<TaskContract> __result)
{
IEnumerator<TaskContract> Func()
{
yield return Yield.It;
}
__result = Func();
return false;
}
}
}

View file

@ -1,8 +1,8 @@
using System;
using GamecraftModdingAPI.Tests;
using TechbloxModdingAPI.Tests;
namespace GamecraftModdingAPI.App
namespace TechbloxModdingAPI.App
{
#if TEST
/// <summary>

View file

@ -1,9 +1,9 @@
using System;
using System.Runtime.Serialization;
namespace GamecraftModdingAPI.App
namespace TechbloxModdingAPI.App
{
public class AppException : GamecraftModdingAPIException
public class AppException : TechbloxModdingAPIException
{
public AppException()
{

View file

@ -0,0 +1,176 @@
using System;
using System.Reflection;
using HarmonyLib;
using RobocraftX.Services;
using UnityEngine;
using RobocraftX.Common;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.App
{
/// <summary>
/// The Techblox application that is running this code right now.
/// </summary>
public class Client
{
public static Client Instance { get; } = new Client();
protected static Func<object> ErrorHandlerInstanceGetter;
protected static Action<object, Error> EnqueueError;
/// <summary>
/// An event that fires whenever the main menu is loaded.
/// </summary>
public static event EventHandler<MenuEventArgs> EnterMenu
{
add => Game.menuEngine.EnterMenu += value;
remove => Game.menuEngine.EnterMenu -= value;
}
/// <summary>
/// An event that fire whenever the main menu is exited.
/// </summary>
public static event EventHandler<MenuEventArgs> ExitMenu
{
add => Game.menuEngine.ExitMenu += value;
remove => Game.menuEngine.ExitMenu -= value;
}
/// <summary>
/// Techblox build version string.
/// Usually this is in the form YYYY.mm.DD.HH.MM.SS
/// </summary>
/// <value>The version.</value>
public string Version
{
get => Application.version;
}
/// <summary>
/// Unity version string.
/// </summary>
/// <value>The unity version.</value>
public string UnityVersion
{
get => Application.unityVersion;
}
/// <summary>
/// Game saves currently visible in the menu.
/// These take a second to completely populate after the EnterMenu event fires.
/// </summary>
/// <value>My games.</value>
public Game[] MyGames
{
get
{
if (!Game.menuEngine.IsInMenu) return Array.Empty<Game>();
return Game.menuEngine.GetMyGames();
}
}
/// <summary>
/// Whether Techblox is in the Main Menu
/// </summary>
/// <value><c>true</c> if in menu; <c>false</c> when loading or in a game.</value>
public bool InMenu
{
get => Game.menuEngine.IsInMenu;
}
/// <summary>
/// Open a popup which prompts the user to click a button.
/// This reuses Techblox's error dialog popup
/// </summary>
/// <param name="popup">The popup to display. Use an instance of SingleChoicePrompt or DualChoicePrompt.</param>
public void PromptUser(Error popup)
{
// if the stuff wasn't mostly set to internal, this would be written as:
// RobocraftX.Services.ErrorHandler.Instance.EqueueError(error);
object errorHandlerInstance = ErrorHandlerInstanceGetter();
EnqueueError(errorHandlerInstance, popup);
}
public void CloseCurrentPrompt()
{
object errorHandlerInstance = ErrorHandlerInstanceGetter();
var popup = GetPopupCloseMethods(errorHandlerInstance);
popup.Close();
}
public void SelectFirstPromptButton()
{
object errorHandlerInstance = ErrorHandlerInstanceGetter();
var popup = GetPopupCloseMethods(errorHandlerInstance);
popup.FirstButton();
}
public void SelectSecondPromptButton()
{
object errorHandlerInstance = ErrorHandlerInstanceGetter();
var popup = GetPopupCloseMethods(errorHandlerInstance);
popup.SecondButton();
}
internal void CloseBetaPopup()
{
Game.menuEngine.CloseBetaPopup();
}
internal static void Init()
{
// this would have been so much simpler if this didn't involve a bunch of internal fields & classes
Type errorHandler = AccessTools.TypeByName("RobocraftX.Services.ErrorHandler");
Type errorHandle = AccessTools.TypeByName("RobocraftX.Services.ErrorHandle");
ErrorHandlerInstanceGetter = (Func<object>) AccessTools.Method("TechbloxModdingAPI.App.Client:GenInstanceGetter")
.MakeGenericMethod(errorHandler)
.Invoke(null, new object[0]);
EnqueueError = (Action<object, Error>) AccessTools.Method("TechbloxModdingAPI.App.Client:GenEnqueueError")
.MakeGenericMethod(errorHandler, errorHandle)
.Invoke(null, new object[0]);
}
// Creating delegates once is faster than reflection every time
// Admittedly, this way is more difficult to code and less readable
private static Func<object> GenInstanceGetter<T>()
{
Type errorHandler = AccessTools.TypeByName("RobocraftX.Services.ErrorHandler");
MethodInfo instance = AccessTools.PropertyGetter(errorHandler, "Instance");
Func<T> getterSimple = (Func<T>) Delegate.CreateDelegate(typeof(Func<T>), null, instance);
Func<object> getterCasted = () => (object) getterSimple();
return getterCasted;
}
private static Action<object, Error> GenEnqueueError<T, TRes>()
{
Type errorHandler = AccessTools.TypeByName("RobocraftX.Services.ErrorHandler");
MethodInfo enqueueError = AccessTools.Method(errorHandler, "EnqueueError");
Func<T, Error, TRes> enqueueSimple =
(Func<T, Error, TRes>) Delegate.CreateDelegate(typeof(Func<T, Error, TRes>), enqueueError);
Action<object, Error> enqueueCasted =
(object instance, Error error) => { enqueueSimple((T) instance, error); };
return enqueueCasted;
}
private static (Action Close, Action FirstButton, Action SecondButton) _errorPopup;
private static (Action Close, Action FirstButton, Action SecondButton) GetPopupCloseMethods(object handler)
{
if (_errorPopup.Close != null)
return _errorPopup;
Type errorHandler = handler.GetType();
FieldInfo field = AccessTools.Field(errorHandler, "errorPopup");
var errorPopup = (ErrorPopup)field.GetValue(handler);
MethodInfo info = AccessTools.Method(errorPopup.GetType(), "ClosePopup");
var close = (Action)Delegate.CreateDelegate(typeof(Action), errorPopup, info);
info = AccessTools.Method(errorPopup.GetType(), "HandleFirstOption");
var first = (Action)Delegate.CreateDelegate(typeof(Action), errorPopup, info);
info = AccessTools.Method(errorPopup.GetType(), "HandleSecondOption");
var second = (Action)Delegate.CreateDelegate(typeof(Action), errorPopup, info);
_errorPopup = (close, first, second);
return _errorPopup;
}
}
}

View file

@ -0,0 +1,67 @@
using System;
using HarmonyLib;
using RobocraftX.Services;
using TechbloxModdingAPI.Tests;
namespace TechbloxModdingAPI.App
{
#if TEST
/// <summary>
/// Client popups tests.
/// Only available in TEST builds.
/// </summary>
[APITestClass]
public static class ClientAlertTest
{
private static DualChoicePrompt popup2 = null;
private static SingleChoicePrompt popup1 = null;
[APITestStartUp]
public static void StartUp2()
{
popup2 = new DualChoicePrompt("This is a test double-button popup",
"The cake is a lie",
"lmao",
() => { },
"kek",
() => { });
}
[APITestStartUp]
public static void StartUp1()
{
popup1 = new SingleChoicePrompt("The cake is a lie",
"This is a test single-button popup",
"qwertyuiop",
() => { });
}
[APITestCase(TestType.Menu)]
public static void TestPopUp2()
{
Client.Instance.PromptUser(popup2);
}
[APITestCase(TestType.Menu)]
public static void TestPopUp1()
{
Client.Instance.PromptUser(popup1);
}
[APITestCase(TestType.Menu)]
public static void TestPopUpClose1()
{
Client.Instance.CloseCurrentPrompt();
}
[APITestCase(TestType.Menu)]
public static void TestPopUpClose2()
{
Client.Instance.CloseCurrentPrompt();
}
}
#endif
}

View file

@ -0,0 +1,27 @@
using System;
namespace TechbloxModdingAPI.App
{
public enum CurrentGameMode
{
None,
/// <summary>
/// Building a world
/// </summary>
Build,
/// <summary>
/// Playing on a map
/// </summary>
Play,
/// <summary>
/// Viewing a prefab (doesn't exist anymore)
/// </summary>
[Obsolete]
View,
/// <summary>
/// Viewing a tutorial (doesn't exist anymore)
/// </summary>
[Obsolete]
Tutorial
}
}

View file

@ -2,17 +2,15 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using RobocraftX.Common;
using RobocraftX.GUI.MyGamesScreen;
using RobocraftX.StateSync;
using Svelto.ECS;
using Techblox.GameSelection;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Tasks;
using GamecraftModdingAPI.Utility;
using TechbloxModdingAPI.Blocks;
using TechbloxModdingAPI.Tasks;
using TechbloxModdingAPI.Utility;
namespace GamecraftModdingAPI.App
namespace TechbloxModdingAPI.App
{
/// <summary>
/// An in-game save.
@ -23,7 +21,7 @@ namespace GamecraftModdingAPI.App
{
// extensible engines
protected static GameGameEngine gameEngine = new GameGameEngine();
protected static GameMenuEngine menuEngine = new GameMenuEngine();
protected internal static GameMenuEngine menuEngine = new GameMenuEngine();
protected static DebugInterfaceEngine debugOverlayEngine = new DebugInterfaceEngine();
protected static GameBuildSimEventEngine buildSimEventEngine = new GameBuildSimEventEngine();
@ -33,7 +31,7 @@ namespace GamecraftModdingAPI.App
private bool hasId = false;
/// <summary>
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.App.Game"/> class.
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.App.Game"/> class.
/// </summary>
/// <param name="id">Menu identifier.</param>
public Game(uint id) : this(new EGID(id, MyGamesScreenExclusiveGroups.MyGames))
@ -41,7 +39,7 @@ namespace GamecraftModdingAPI.App
}
/// <summary>
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.App.Game"/> class.
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.App.Game"/> class.
/// </summary>
/// <param name="id">Menu identifier.</param>
public Game(EGID id)
@ -54,7 +52,7 @@ namespace GamecraftModdingAPI.App
}
/// <summary>
/// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.App.Game"/> class without id.
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.App.Game"/> class without id.
/// This is assumed to be the current game.
/// </summary>
public Game()
@ -118,7 +116,7 @@ namespace GamecraftModdingAPI.App
/// <summary>
/// An event that fires right before a game returns to the main menu.
/// At this point, Gamecraft is transitioning state so many things are invalid/unstable here.
/// At this point, Techblox is transitioning state so many things are invalid/unstable here.
/// </summary>
public static event EventHandler<GameEventArgs> Exit
{
@ -165,7 +163,7 @@ namespace GamecraftModdingAPI.App
{
if (!VerifyMode()) return null;
if (menuMode) return menuEngine.GetGameInfo(EGID).GameName;
return GameMode.SaveGameDetails.Name;
return gameEngine.GetGameData().saveName;
}
set
@ -174,11 +172,7 @@ namespace GamecraftModdingAPI.App
if (menuMode)
{
menuEngine.SetGameName(EGID, value);
}
else
{
GameMode.SaveGameDetails.Name = value;
}
} // Save details are directly saved from user input or not changed at all when in game
}
}
@ -201,11 +195,7 @@ namespace GamecraftModdingAPI.App
if (menuMode)
{
menuEngine.SetGameDescription(EGID, value);
}
else
{
// No description exists in-game
}
} // No description exists in-game
}
}
@ -219,7 +209,7 @@ namespace GamecraftModdingAPI.App
{
if (!VerifyMode()) return null;
if (menuMode) return menuEngine.GetGameInfo(EGID).SavedGamePath;
return GameMode.SaveGameDetails.Folder;
return gameEngine.GetGameData().gameID;
}
set
@ -229,11 +219,6 @@ namespace GamecraftModdingAPI.App
{
menuEngine.GetGameInfo(EGID).SavedGamePath.Set(value);
}
else
{
// this likely breaks things
GameMode.SaveGameDetails = new SaveGameDetails(GameMode.SaveGameDetails.Name, value, GameMode.SaveGameDetails.WorkshopId);
}
}
}
@ -242,28 +227,16 @@ namespace GamecraftModdingAPI.App
/// In most cases this is invalid and returns 0, so this can be ignored.
/// </summary>
/// <value>The workshop identifier.</value>
[Obsolete]
public ulong WorkshopId
{
get
{
if (!VerifyMode()) return 0uL;
if (menuMode) return 0uL; // MyGames don't have workshop IDs
return GameMode.SaveGameDetails.WorkshopId;
return 0uL; // Not supported anymore
}
set
{
VerifyMode();
if (menuMode)
{
// MyGames don't have workshop IDs
// menuEngine.GetGameInfo(EGID).GameName.Set(value);
}
else
{
// this likely breaks things
GameMode.SaveGameDetails = new SaveGameDetails(GameMode.SaveGameDetails.Name, GameMode.SaveGameDetails.Folder, value);
}
}
}
@ -335,6 +308,18 @@ namespace GamecraftModdingAPI.App
gameEngine.ToggleTimeMode();
}
/// <summary>
/// The mode of the game.
/// </summary>
public CurrentGameMode Mode
{
get
{
if (menuMode || !VerifyMode()) return CurrentGameMode.None;
return gameEngine.GetGameData().gameMode == GameMode.CreateWorld ? CurrentGameMode.Build : CurrentGameMode.Play;
}
}
/// <summary>
/// Load the game save.
/// This happens asynchronously, so when this method returns the game not loaded yet.
@ -384,19 +369,20 @@ namespace GamecraftModdingAPI.App
/// <summary>
/// Add information to the in-game debug display.
/// When this object is garbage collected, this debug info is automatically removed.
/// When this object is garbage collected, this debug info is automatically removed.
/// The provided getter function is called each frame so make sure it returns quickly.
/// </summary>
/// <param name="id">Debug info identifier.</param>
/// <param name="contentGetter">Content getter.</param>
public void AddDebugInfo(string id, Func<string> contentGetter)
/// <param name="contentGetter">A function that returns the current information.</param>
public void AddDebugInfo(string id, Func<string> contentGetter)
{
if (!VerifyMode()) return;
if (menuMode)
{
throw new GameNotFoundException("Game object references a menu item but AddDebugInfo only works on the currently-loaded game");
}
debugOverlayEngine.SetInfo(id, contentGetter);
debugIds.Add(id);
if (!VerifyMode()) return;
if (menuMode)
{
throw new GameNotFoundException("Game object references a menu item but AddDebugInfo only works on the currently-loaded game");
}
debugOverlayEngine.SetInfo("game_" + id, contentGetter);
debugIds.Add(id);
}
/// <summary>
@ -406,14 +392,36 @@ namespace GamecraftModdingAPI.App
/// <param name="id">Debug info identifier.</param>
public bool RemoveDebugInfo(string id)
{
if (!VerifyMode()) return false;
if (menuMode)
{
throw new GameNotFoundException("Game object references a menu item but RemoveDebugInfo only works on the currently-loaded game");
}
if (!debugIds.Contains(id)) return false;
debugOverlayEngine.RemoveInfo(id);
return debugIds.Remove(id);
if (!VerifyMode()) return false;
if (menuMode)
{
throw new GameNotFoundException("Game object references a menu item but RemoveDebugInfo only works on the currently-loaded game");
}
if (!debugIds.Contains(id)) return false;
debugOverlayEngine.RemoveInfo("game_" + id);
return debugIds.Remove(id);
}
/// <summary>
/// Add information to the in-game debug display.
/// This debug info will be present for all games until it is manually removed.
/// The provided getter function is called each frame so make sure it returns quickly.
/// </summary>
/// <param name="id">Debug info identifier.</param>
/// <param name="contentGetter">A function that returns the current information.</param>
public static void AddPersistentDebugInfo(string id, Func<string> contentGetter)
{
debugOverlayEngine.SetInfo("persistent_" + id, contentGetter);
}
/// <summary>
/// Remove persistent information from the in-game debug display.
/// </summary>
/// <returns><c>true</c>, if debug info was removed, <c>false</c> otherwise.</returns>
/// <param name="id">Debug info identifier.</param>
public static bool RemovePersistentDebugInfo(string id)
{
return debugOverlayEngine.RemoveInfo("persistent_" + id);
}
/// <summary>
@ -433,11 +441,20 @@ namespace GamecraftModdingAPI.App
Block[] blocks = new Block[blockEGIDs.Length];
for (int b = 0; b < blockEGIDs.Length; b++)
{
blocks[b] = new Block(blockEGIDs[b]);
blocks[b] = Block.New(blockEGIDs[b]);
}
return blocks;
}
/// <summary>
/// Enable the screenshot taker for updating the game's screenshot. Breaks the pause menu in a new save.
/// </summary>
public void EnableScreenshotTaker()
{
if (!VerifyMode()) return;
gameEngine.EnableScreenshotTaker();
}
~Game()
{
foreach (string id in debugIds)
@ -466,12 +483,8 @@ namespace GamecraftModdingAPI.App
{
GameEngineManager.AddGameEngine(gameEngine);
GameEngineManager.AddGameEngine(debugOverlayEngine);
GameEngineManager.AddGameEngine(buildSimEventEngine);
MenuEngineManager.AddMenuEngine(menuEngine);
}
internal static void InitDeterministic(StateSyncRegistrationHelper stateSyncReg)
{
stateSyncReg.AddDeterministicEngine(buildSimEventEngine);
}
}
}

View file

@ -4,19 +4,18 @@ using RobocraftX.Common;
using RobocraftX.StateSync;
using Svelto.ECS;
using Unity.Jobs;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.App
namespace TechbloxModdingAPI.App
{
public class GameBuildSimEventEngine : IApiEngine, IUnorderedInitializeOnTimeRunningModeEntered, IUnorderedInitializeOnTimeStoppedModeEntered
{
public event EventHandler<GameEventArgs> SimulationMode;
public WrappedHandler<GameEventArgs> SimulationMode;
public event EventHandler<GameEventArgs> BuildMode;
public WrappedHandler<GameEventArgs> BuildMode;
public string Name => "GamecraftModdingAPIBuildSimEventGameEngine";
public string Name => "TechbloxModdingAPIBuildSimEventGameEngine";
public bool isRemovable => false;
@ -28,13 +27,15 @@ namespace GamecraftModdingAPI.App
public JobHandle OnInitializeTimeRunningMode(JobHandle inputDeps)
{
ExceptionUtil.InvokeEvent(SimulationMode, this, new GameEventArgs { GameName = GameMode.SaveGameDetails.Name, GamePath = GameMode.SaveGameDetails.Folder });
Console.WriteLine("Init time running mode");
SimulationMode.Invoke(this, new GameEventArgs { GameName = "", GamePath = "" }); // TODO
return inputDeps;
}
public JobHandle OnInitializeTimeStoppedMode(JobHandle inputDeps)
{
ExceptionUtil.InvokeEvent(BuildMode, this, new GameEventArgs { GameName = GameMode.SaveGameDetails.Name, GamePath = GameMode.SaveGameDetails.Folder });
Console.WriteLine("Init time stopped mode");
BuildMode.Invoke(this, new GameEventArgs { GameName = "", GamePath = "" });
return inputDeps;
}
}

View file

@ -0,0 +1,194 @@
using System.Collections.Generic;
using HarmonyLib;
using RobocraftX;
using RobocraftX.Common;
using RobocraftX.Schedulers;
using RobocraftX.SimulationModeState;
using Svelto.ECS;
using Svelto.Tasks;
using Svelto.Tasks.Lean;
using RobocraftX.Blocks;
using RobocraftX.Common.Loading;
using RobocraftX.Multiplayer;
using RobocraftX.ScreenshotTaker;
using Techblox.Environment.Transition;
using Techblox.GameSelection;
using TechbloxModdingAPI.Blocks;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Input;
using TechbloxModdingAPI.Players;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.App
{
public class GameGameEngine : IApiEngine, IReactOnAddAndRemove<LoadingActionEntityStruct>
{
public WrappedHandler<GameEventArgs> EnterGame;
public WrappedHandler<GameEventArgs> ExitGame;
public string Name => "TechbloxModdingAPIGameInfoMenuEngine";
public bool isRemovable => false;
public EntitiesDB entitiesDB { set; private get; }
private bool enteredGame;
private bool loadingFinished;
private bool playerJoined;
public void Dispose()
{
if (GameReloadedPatch.IsReload)
return; // Toggling time mode
ExitGame.Invoke(this, new GameEventArgs { GameName = GetGameData().saveName, GamePath = GetGameData().gameID });
IsInGame = false;
loadingFinished = false;
playerJoined = false;
enteredGame = false;
}
public void Ready()
{
if (GameReloadedPatch.IsReload)
return; // Toggling time mode
enteredGame = true;
Player.Joined += OnPlayerJoined;
}
private void OnPlayerJoined(object sender, PlayerEventArgs args)
{
if (args.Player.Type != PlayerType.Local) return;
playerJoined = true;
Player.Joined -= OnPlayerJoined;
CheckJoinEvent();
}
// game functionality
public bool IsInGame
{
get;
private set;
} = false;
public void ExitCurrentGame(bool async = false)
{
if (async)
{
ExitCurrentGameAsync().RunOn(ClientLean.EveryFrameStepRunner_TimeRunningAndStopped);
}
else
{
entitiesDB.QueryEntity<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID).WantsToQuit = true;
entitiesDB.PublishEntityChange<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
}
}
public IEnumerator<TaskContract> ExitCurrentGameAsync()
{
/*
while (Lean.EveryFrameStepRunner_RUNS_IN_TIME_STOPPED_AND_RUNNING.isStopping) { yield return Yield.It; }
AccessTools.Method(typeof(FullGameCompositionRoot), "SwitchToMenu").Invoke(FullGameFields.Instance, new object[0]);*/
yield return Yield.It;
entitiesDB.QueryEntity<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID).WantsToQuit = true;
entitiesDB.PublishEntityChange<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
}
public void SaveCurrentGame()
{
ref GameSceneEntityStruct gses = ref entitiesDB.QueryEntity<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
gses.LoadAfterSaving = false;
gses.SaveNow = true;
entitiesDB.PublishEntityChange<GameSceneEntityStruct>(CommonExclusiveGroups.GameSceneEGID);
}
public bool IsTimeRunningMode()
{
return TimeRunningModeUtil.IsTimeRunningMode(entitiesDB);
}
public bool IsTimeStoppedMode()
{
return TimeRunningModeUtil.IsTimeStoppedMode(entitiesDB);
}
public void ToggleTimeMode()
{
if (TimeRunningModeUtil.IsTimeStoppedMode(entitiesDB))
FakeInput.ActionInput(toggleMode: true);
else
{
IEnumerator<TaskContract> ReloadBuildModeTask()
{
SwitchAnimationUtil.Start(entitiesDB);
while (SwitchAnimationUtil.IsFadeOutActive(entitiesDB))
yield return (TaskContract)Yield.It;
FullGameFields._multiplayerParams.MultiplayerMode = MultiplayerMode.SinglePlayer;
AccessTools.Method(typeof(FullGameCompositionRoot), "ReloadGame")
.Invoke(FullGameFields.Instance, new object[] { });
}
ReloadBuildModeTask().RunOn(ClientLean.UIScheduler);
}
}
public EGID[] GetAllBlocksInGame(BlockIDs filter = BlockIDs.Invalid)
{
var allBlocks = entitiesDB.QueryEntities<BlockTagEntityStruct>();
List<EGID> blockEGIDs = new List<EGID>();
foreach (var (blocks, _) in allBlocks)
{
var (buffer, count) = blocks.ToBuffer();
for (int i = 0; i < count; i++)
{
uint dbid;
if (filter == BlockIDs.Invalid)
dbid = (uint)filter;
else
dbid = entitiesDB.QueryEntity<DBEntityStruct>(buffer[i].ID).DBID;
if (dbid == (ulong)filter)
blockEGIDs.Add(buffer[i].ID);
}
}
return blockEGIDs.ToArray();
}
public void EnableScreenshotTaker()
{
ref var local = ref entitiesDB.QueryEntity<ScreenshotModeEntityStruct>(ScreenshotTakerEgids.ScreenshotTaker);
if (local.enabled)
return;
local.enabled = true;
entitiesDB.PublishEntityChange<ScreenshotModeEntityStruct>(ScreenshotTakerEgids.ScreenshotTaker);
}
public GameSelectionComponent GetGameData()
{
return entitiesDB.QueryEntity<GameSelectionComponent>(GameSelectionConstants.GameSelectionEGID);
}
public void Add(ref LoadingActionEntityStruct entityComponent, EGID egid)
{
}
public void Remove(ref LoadingActionEntityStruct entityComponent, EGID egid)
{ // Finished loading
if (!enteredGame) return;
enteredGame = false;
loadingFinished = true;
CheckJoinEvent();
}
private void CheckJoinEvent()
{
if (!loadingFinished || !playerJoined) return;
EnterGame.Invoke(this, new GameEventArgs { GameName = GetGameData().saveName, GamePath = GetGameData().gameID });
IsInGame = true;
}
}
}

View file

@ -0,0 +1,209 @@
using System;
using System.Reflection;
using HarmonyLib;
using RobocraftX;
using RobocraftX.GUI;
using RobocraftX.GUI.MyGamesScreen;
using RobocraftX.Multiplayer;
using Svelto.ECS;
using Svelto.ECS.Experimental;
using Techblox.GameSelection;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.App
{
public class GameMenuEngine : IFactoryEngine
{
public WrappedHandler<MenuEventArgs> EnterMenu;
public WrappedHandler<MenuEventArgs> ExitMenu;
public IEntityFactory Factory { set; private get; }
public string Name => "TechbloxModdingAPIGameInfoGameEngine";
public bool isRemovable => false;
public EntitiesDB entitiesDB { set; private get; }
public GameMenuEngine()
{
MenuEnteredEnginePatch.EnteredExitedMenu = () =>
{
if (IsInMenu)
EnterMenu.Invoke(this, new MenuEventArgs { });
else
ExitMenu.Invoke(this, new MenuEventArgs { });
};
}
public void Dispose()
{
}
public void Ready()
{
MenuEnteredEnginePatch.IsInMenu = true; // At first it uses ActivateMenu(), then GoToMenu() which is patched
MenuEnteredEnginePatch.EnteredExitedMenu();
}
// game functionality
public bool IsInMenu => MenuEnteredEnginePatch.IsInMenu;
public Game[] GetMyGames()
{
EntityCollection<MyGameDataEntityStruct> mgsevs = entitiesDB.QueryEntities<MyGameDataEntityStruct>(MyGamesScreenExclusiveGroups.MyGames);
var mgsevsB = mgsevs.ToBuffer().buffer;
Game[] games = new Game[mgsevs.count];
for (int i = 0; i < mgsevs.count; i++)
{
Utility.Logging.MetaDebugLog($"Found game named {mgsevsB[i].GameName}");
games[i] = new Game(mgsevsB[i].ID);
}
return games;
}
public bool CreateMyGame(EGID id, string path = "", uint thumbnailId = 0, string gameName = "", string creatorName = "", string description = "", long createdDate = 0L)
{
EntityInitializer eci = Factory.BuildEntity<MyGameDataEntityDescriptor_DamnItFJWhyDidYouMakeThisInternal>(id);
eci.Init(new MyGameDataEntityStruct
{
SavedGamePath = new ECSString(path),
ThumbnailId = thumbnailId,
GameName = new ECSString(gameName),
CreatorName = new ECSString(creatorName),
GameDescription = new ECSString(description),
CreatedDate = createdDate,
});
// entitiesDB.PublishEntityChange<MyGameDataEntityStruct>(id); // this will always fail
return true;
}
public uint HighestID()
{
EntityCollection<MyGameDataEntityStruct> games = entitiesDB.QueryEntities<MyGameDataEntityStruct>(MyGamesScreenExclusiveGroups.MyGames);
var gamesB = games.ToBuffer().buffer;
uint max = 0;
for (int i = 0; i < games.count; i++)
{
if (gamesB[i].ID.entityID > max)
{
max = gamesB[i].ID.entityID;
}
}
return max;
}
public bool EnterGame(EGID id)
{
if (!ExistsGameInfo(id)) return false;
ref MyGameDataEntityStruct mgdes = ref GetGameInfo(id);
return EnterGame(mgdes.GameName, mgdes.FileId);
}
public bool EnterGame(ECSString gameName, string fileId, bool autoEnterSim = false)
{
FullGameFields._multiplayerParams.MultiplayerMode = MultiplayerMode.SinglePlayer;
ref var selection = ref entitiesDB.QueryEntity<GameSelectionComponent>(GameSelectionConstants.GameSelectionEGID);
selection.userContentID.Set(fileId);
selection.triggerStart = true;
selection.saveType = SaveType.ExistingSave;
selection.saveName = gameName;
selection.gameMode = GameMode.PlayGame;
selection.gameID.Set("GAMEID_Road_Track"); //TODO: Expose to the API
return true;
}
public bool SetGameName(EGID id, string name)
{
if (!ExistsGameInfo(id)) return false;
GetGameInfo(id).GameName.Set(name);
GetGameViewInfo(id).MyGamesSlotComponent.GameName = StringUtil.SanitiseString(name);
return true;
}
public bool SetGameDescription(EGID id, string name)
{
if (!ExistsGameInfo(id)) return false;
GetGameInfo(id).GameDescription.Set(name);
GetGameViewInfo(id).MyGamesSlotComponent.GameDescription = StringUtil.SanitiseString(name);
return true;
}
public bool ExistsGameInfo(EGID id)
{
return entitiesDB.Exists<MyGameDataEntityStruct>(id);
}
public ref MyGameDataEntityStruct GetGameInfo(EGID id)
{
return ref GetComponent<MyGameDataEntityStruct>(id);
}
public dynamic GetGameViewInfo(EGID id)
{
dynamic structOptional = AccessTools.Method("TechbloxModdingAPI.Utility.NativeApiExtensions:QueryEntityOptional", new []{typeof(EntitiesDB), typeof(EGID)})
.MakeGenericMethod(AccessTools.TypeByName("RobocraftX.GUI.MyGamesScreen.MyGamesSlotEntityViewStruct"))
.Invoke(null, new object[] {entitiesDB, new EGID(id.entityID, MyGamesScreenExclusiveGroups.GameSlotGuiEntities)});
if (structOptional == null) throw new Exception("Could not get game slot entity");
return structOptional ? structOptional : null;
}
public ref T GetComponent<T>(EGID id) where T: unmanaged, IEntityComponent
{
return ref entitiesDB.QueryEntity<T>(id);
}
internal void CloseBetaPopup()
{
var (buffer, count) = entitiesDB.QueryEntities<TogglePanelButtonEntityViewStruct>(ExclusiveGroup.Search("BetaPopup"));
for (int index = 0; index < count; ++index)
{
entitiesDB.QueryEntity<GUIEntityViewStruct>(buffer[index].TogglePanelButtonComponent.targetPanel)
.guiRoot.enabled = false;
}
}
}
internal class MyGameDataEntityDescriptor_DamnItFJWhyDidYouMakeThisInternal : GenericEntityDescriptor<MyGameDataEntityStruct> { }
[HarmonyPatch]
static class MenuEnteredEnginePatch
{
internal static bool IsInMenu;
internal static Action EnteredExitedMenu;
public static void Postfix()
{
IsInMenu = true;
EnteredExitedMenu();
}
public static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(FullGameCompositionRoot), "SwitchToMenu");
}
}
[HarmonyPatch]
static class MenuExitedEnginePatch
{
public static void Prefix()
{
MenuEnteredEnginePatch.IsInMenu = false;
MenuEnteredEnginePatch.EnteredExitedMenu();
}
public static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(FullGameCompositionRoot), "SwitchToGame");
}
}
public struct MenuEventArgs
{
}
}

View file

@ -0,0 +1,27 @@
using System;
using HarmonyLib;
using RobocraftX.Services;
namespace TechbloxModdingAPI.App
{
public class DualChoicePrompt : MultiChoiceError
{
public DualChoicePrompt(string errorMessage, string title, string firstButtonText, Action firstButtonAction, string secondButtonText, Action secondButtonAction) : base(errorMessage, firstButtonText, firstButtonAction, secondButtonText, secondButtonAction)
{
// internal readonly field smh
new Traverse(this).Field<string>("Title").Value = title;
}
}
public class SingleChoicePrompt : SingleChoiceError
{
public SingleChoicePrompt(string errorMessage, string buttonText, Action buttonClickAction) : base(errorMessage, buttonText, buttonClickAction)
{
}
public SingleChoicePrompt(string titleText, string errorMessage, string buttonText, Action buttonClickAction) : base(titleText, errorMessage, buttonText, buttonClickAction)
{
}
}
}

494
TechbloxModdingAPI/Block.cs Normal file
View file

@ -0,0 +1,494 @@
using System;
using System.Collections.Generic;
using DataLoader;
using Gamecraft.Blocks.BlockGroups;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using RobocraftX.Common;
using RobocraftX.Blocks;
using Unity.Mathematics;
using HarmonyLib;
using RobocraftX.PilotSeat;
using RobocraftX.Rendering;
using Techblox.BlockLabels;
using TechbloxModdingAPI.Blocks;
using TechbloxModdingAPI.Blocks.Engines;
using TechbloxModdingAPI.Tests;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI
{
/// <summary>
/// A single (perhaps scaled) block. Properties may return default values if the block is removed and then setting them is ignored.
/// For specific block type operations, use the specialised block classes in the TechbloxModdingAPI.Blocks namespace.
/// </summary>
public class Block : EcsObjectBase, IEquatable<Block>, IEquatable<EGID>
{
protected static readonly PlacementEngine PlacementEngine = new PlacementEngine();
protected static readonly MovementEngine MovementEngine = new MovementEngine();
protected static readonly RotationEngine RotationEngine = new RotationEngine();
protected static readonly RemovalEngine RemovalEngine = new RemovalEngine();
protected static readonly SignalEngine SignalEngine = new SignalEngine();
protected static readonly BlockEventsEngine BlockEventsEngine = new BlockEventsEngine();
protected static readonly ScalingEngine ScalingEngine = new ScalingEngine();
protected static readonly BlockCloneEngine BlockCloneEngine = new BlockCloneEngine();
protected internal static readonly BlockEngine BlockEngine = new BlockEngine();
/// <summary>
/// Place a new block at the given position. If scaled, position means the center of the block. The default block size is 0.2 in terms of position.
/// Place blocks next to each other to connect them.
/// The placed block will be a complete block with a placement grid and collision which will be saved along with the game.
/// </summary>
/// <param name="block">The block's type</param>
/// <param name="position">The block's position - default block size is 0.2</param>
/// <param name="autoWire">Whether the block should be auto-wired (if functional)</param>
/// <param name="player">The player who placed the block</param>
/// <param name="force"></param>
/// <returns>The placed block or null if failed</returns>
public static Block PlaceNew(BlockIDs block, float3 position, bool autoWire = false, Player player = null,
bool force = false)
{
if (PlacementEngine.IsInGame && (GameState.IsBuildMode() || force))
{
var initializer = PlacementEngine.PlaceBlock(block, position, player, autoWire);
var egid = initializer.EGID;
var bl = New(egid);
bl.InitData = initializer;
Placed += bl.OnPlacedInit;
return bl;
}
return null;
}
/// <summary>
/// Returns the most recently placed block.
/// </summary>
/// <returns>The block object or null if doesn't exist</returns>
public static Block GetLastPlacedBlock()
{
uint lastBlockID = (uint) AccessTools.Field(typeof(CommonExclusiveGroups), "_nextBlockEntityID").GetValue(null) - 1;
EGID? egid = BlockEngine.FindBlockEGID(lastBlockID);
return egid.HasValue ? New(egid.Value) : null;
}
/*public static Block CreateGhostBlock()
{
return BlockGroup._engine.BuildGhostChild();
}*/
/// <summary>
/// An event that fires each time a block is placed.
/// </summary>
public static event EventHandler<BlockPlacedRemovedEventArgs> Placed
{ //TODO: Rename and add instance version in 3.0
add => BlockEventsEngine.Placed += value;
remove => BlockEventsEngine.Placed -= value;
}
/// <summary>
/// An event that fires each time a block is removed.
/// </summary>
public static event EventHandler<BlockPlacedRemovedEventArgs> Removed
{
add => BlockEventsEngine.Removed += value;
remove => BlockEventsEngine.Removed -= value;
}
private static readonly Dictionary<ExclusiveBuildGroup, (Func<EGID, Block> Constructor, Type Type)> GroupToConstructor =
new Dictionary<ExclusiveBuildGroup, (Func<EGID, Block>, Type)>
{
{CommonExclusiveGroups.DAMPEDSPRING_BLOCK_GROUP, (id => new DampedSpring(id), typeof(DampedSpring))},
{CommonExclusiveGroups.ENGINE_BLOCK_BUILD_GROUP, (id => new Engine(id), typeof(Engine))},
{CommonExclusiveGroups.LOGIC_BLOCK_GROUP, (id => new LogicGate(id), typeof(LogicGate))},
{CommonExclusiveGroups.PISTON_BLOCK_GROUP, (id => new Piston(id), typeof(Piston))},
{CommonExclusiveGroups.SERVO_BLOCK_GROUP, (id => new Servo(id), typeof(Servo))},
{CommonExclusiveGroups.WHEELRIG_BLOCK_BUILD_GROUP, (id => new WheelRig(id), typeof(WheelRig))}
};
static Block()
{
foreach (var group in SeatGroups.SEATS_BLOCK_GROUPS) // Adds driver and passenger seats, occupied and unoccupied
GroupToConstructor.Add(group, (id => new Seat(id), typeof(Seat)));
}
/// <summary>
/// Returns a correctly typed instance of this block. The instances are shared for a specific block.
/// If an instance is no longer referenced a new instance is returned.
/// </summary>
/// <param name="egid">The EGID of the block</param>
/// <param name="signaling">Whether the block is definitely a signaling block</param>
/// <returns></returns>
internal static Block New(EGID egid, bool signaling = false)
{
if (egid == default) return null;
if (GroupToConstructor.ContainsKey(egid.groupID))
{
var (constructor, type) = GroupToConstructor[egid.groupID];
return GetInstance(egid, constructor, type);
}
return signaling
? GetInstance(egid, e => new SignalingBlock(e))
: GetInstance(egid, e => new Block(e));
}
public Block(EGID id) : base(id)
{
Type expectedType;
if (GroupToConstructor.ContainsKey(id.groupID) &&
!GetType().IsAssignableFrom(expectedType = GroupToConstructor[id.groupID].Type))
throw new BlockSpecializationException($"Incorrect block type! Expected: {expectedType} Actual: {GetType()}");
}
/// <summary>
/// This overload searches for the correct group the block is in.
/// It will throw an exception if the block doesn't exist.
/// Use the EGID constructor where possible or subclasses of Block as those specify the group.
/// </summary>
public Block(uint id) : this(BlockEngine.FindBlockEGID(id)
?? throw new BlockTypeException(
"Could not find the appropriate group for the block." +
" The block probably doesn't exist or hasn't been submitted."))
{
}
/// <summary>
/// Places a new block in the world.
/// </summary>
/// <param name="type">The block's type</param>
/// <param name="position">The block's position (a block is 0.2 wide in terms of position)</param>
/// <param name="autoWire">Whether the block should be auto-wired (if functional)</param>
/// <param name="player">The player who placed the block</param>
/// <param name="force">Place even if not in build mode</param>
public Block(BlockIDs type, float3 position, bool autoWire = false, Player player = null, bool force = false)
: base(block =>
{
if (!PlacementEngine.IsInGame || !GameState.IsBuildMode() && !force)
throw new BlockException("Blocks can only be placed in build mode.");
var initializer = PlacementEngine.PlaceBlock(type, position, player, autoWire);
block.InitData = initializer;
Placed += ((Block)block).OnPlacedInit;
return initializer.EGID;
})
{
}
private EGID copiedFrom;
/// <summary>
/// The block's current position or zero if the block no longer exists.
/// A block is 0.2 wide by default in terms of position.
/// </summary>
public float3 Position
{
get => MovementEngine.GetPosition(this);
set
{
MovementEngine.MoveBlock(this, value);
if (blockGroup != null)
blockGroup.PosAndRotCalculated = false;
BlockEngine.UpdateDisplayedBlock(Id);
}
}
/// <summary>
/// The block's current rotation in degrees or zero if the block doesn't exist.
/// </summary>
public float3 Rotation
{
get => RotationEngine.GetRotation(this);
set
{
RotationEngine.RotateBlock(this, value);
if (blockGroup != null)
blockGroup.PosAndRotCalculated = false;
BlockEngine.UpdateDisplayedBlock(Id);
}
}
/// <summary>
/// The block's non-uniform scale or zero if the block's invalid. Independent of the uniform scaling.
/// The default scale of 1 means 0.2 in terms of position.
/// </summary>
public float3 Scale
{
get => BlockEngine.GetBlockInfo<ScalingEntityStruct>(this).scale;
set
{
int uscale = UniformScale;
if (value.x < 4e-5) value.x = uscale;
if (value.y < 4e-5) value.y = uscale;
if (value.z < 4e-5) value.z = uscale;
BlockEngine.GetBlockInfo<ScalingEntityStruct>(this).scale = value;
//BlockEngine.GetBlockInfo<GridScaleStruct>(this).gridScale = value - (int3) value + 1;
if (!Exists) return; //UpdateCollision needs the block to exist
ScalingEngine.UpdateCollision(Id);
BlockEngine.UpdateDisplayedBlock(Id);
}
}
/// <summary>
/// The block's uniform scale or zero if the block's invalid. Also sets the non-uniform scale.
/// The default scale of 1 means 0.2 in terms of position.
/// </summary>
public int UniformScale
{
get => BlockEngine.GetBlockInfo<UniformBlockScaleEntityStruct>(this).scaleFactor;
set
{
if (value < 1) value = 1;
BlockEngine.GetBlockInfo<UniformBlockScaleEntityStruct>(this).scaleFactor = value;
Scale = new float3(value, value, value);
}
}
/**
* Whether the block is flipped.
*/
public bool Flipped
{
get => BlockEngine.GetBlockInfo<ScalingEntityStruct>(this).scale.x < 0;
set
{
ref var st = ref BlockEngine.GetBlockInfo<ScalingEntityStruct>(this);
st.scale.x = math.abs(st.scale.x) * (value ? -1 : 1);
BlockEngine.UpdatePrefab(this, (byte) Material, value);
}
}
/// <summary>
/// The block's type (ID). Returns BlockIDs.Invalid if the block doesn't exist anymore.
/// </summary>
public BlockIDs Type
{
get
{
var opt = BlockEngine.GetBlockInfoOptional<DBEntityStruct>(this);
return opt ? (BlockIDs) opt.Get().DBID : BlockIDs.Invalid;
}
}
/// <summary>
/// The block's color. Returns BlockColors.Default if the block no longer exists.
/// </summary>
public BlockColor Color
{
get
{
var opt = BlockEngine.GetBlockInfoOptional<ColourParameterEntityStruct>(this);
return new BlockColor(opt ? opt.Get().indexInPalette : byte.MaxValue);
}
set
{
if (value.Color == BlockColors.Default)
value = new BlockColor(FullGameFields._dataDb.TryGetValue((int) Type, out CubeListData cld)
? cld.DefaultColour
: throw new BlockTypeException("Unknown block type! Could not set default color."));
ref var color = ref BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(this);
color.indexInPalette = value.Index;
color.hasNetworkChange = true;
color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette); //Setting to 255 results in black
}
}
/// <summary>
/// The block's exact color. Gets reset to the palette color (Color property) after reentering the game.
/// </summary>
public float4 CustomColor
{
get => BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(this).paletteColour;
set
{
ref var color = ref BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(this);
color.paletteColour = value;
color.hasNetworkChange = true;
}
}
/**
* The block's material.
*/
public BlockMaterial Material
{
get
{
var opt = BlockEngine.GetBlockInfoOptional<CubeMaterialStruct>(this);
return opt ? (BlockMaterial) opt.Get().materialId : BlockMaterial.Default;
}
set
{
byte val = (byte) value;
if (value == BlockMaterial.Default)
val = FullGameFields._dataDb.TryGetValue((int) Type, out CubeListData cld)
? cld.DefaultMaterialID
: throw new BlockTypeException("Unknown block type! Could not set default material.");
if (!FullGameFields._dataDb.ContainsKey<MaterialPropertiesData>(val))
throw new BlockException($"Block material {value} does not exist!");
ref var comp = ref BlockEngine.GetBlockInfo<CubeMaterialStruct>(this);
if (comp.materialId == val)
return;
comp.materialId = val;
BlockEngine.UpdatePrefab(this, val, Flipped); //The default causes the screen to go black
}
}
/// <summary>
/// The text displayed on the block if applicable, or null.
/// Setting it is temporary to the session, it won't be saved.
/// </summary>
[TestValue(null)]
public string Label
{
get => BlockEngine.GetBlockInfo<LabelResourceIDComponent>(this).ToString(); //TODO: Block labels
set
{ //TODO
}
}
private BlockGroup blockGroup;
/// <summary>
/// Returns the block group this block is a part of. Block groups can also be placed using blueprints.
/// Returns null if not part of a group, although all blocks should have their own by default.<br />
/// Setting the group after the block has been initialized will not update everything properly,
/// so you can only set this property on blocks newly placed by your code.<br />
/// To set it for existing blocks, you can use the Copy() method and set the property on the resulting block
/// (and remove this block).
/// </summary>
public BlockGroup BlockGroup
{
get
{
if (blockGroup != null) return blockGroup;
var bgec = BlockEngine.GetBlockInfo<BlockGroupEntityComponent>(this);
return blockGroup = bgec.currentBlockGroup == -1 ? null : new BlockGroup(bgec.currentBlockGroup, this);
}
set
{
if (Exists)
{
Logging.LogWarning("Attempted to set group of existing block. This is not supported."
+ " Copy the block and set the group of the resulting block.");
return;
}
blockGroup?.RemoveInternal(this);
if (!InitData.Valid)
return;
BlockEngine.GetBlockInfo<BlockGroupEntityComponent>(this).currentBlockGroup = (int?) value?.Id.entityID ?? -1;
value?.AddInternal(this);
blockGroup = value;
}
}
/// <summary>
/// Whether the block should be static in simulation. If set, it cannot be moved. The effect is temporary, it will not be saved with the block.
/// </summary>
public bool Static
{
get => BlockEngine.GetBlockInfo<BlockStaticComponent>(this).isStatic;
set => BlockEngine.GetBlockInfo<BlockStaticComponent>(this).isStatic = value;
}
/// <summary>
/// Whether the block exists. The other properties will return a default value if the block doesn't exist.
/// If the block was just placed, then this will also return false but the properties will work correctly.
/// </summary>
public bool Exists => BlockEngine.BlockExists(Id);
/// <summary>
/// Returns an array of blocks that are connected to this one. Returns an empty array if the block doesn't exist.
/// </summary>
public Block[] GetConnectedCubes() => BlockEngine.GetConnectedBlocks(Id);
/// <summary>
/// Removes this block.
/// </summary>
/// <returns>True if the block exists and could be removed.</returns>
public bool Remove() => RemovalEngine.RemoveBlock(Id);
/// <summary>
/// Returns the rigid body of the chunk of blocks this one belongs to during simulation.
/// Can be used to apply forces or move the block around while the simulation is running.
/// </summary>
/// <returns>The SimBody of the chunk or null if the block doesn't exist or not in simulation mode.</returns>
public SimBody GetSimBody()
{
var st = BlockEngine.GetBlockInfo<GridConnectionsEntityStruct>(this);
return st.machineRigidBodyId != uint.MaxValue
? new SimBody(st.machineRigidBodyId, st.clusterId)
: null;
}
/// <summary>
/// Creates a copy of the block in the game with the same properties, stats and wires.
/// </summary>
/// <returns></returns>
public Block Copy()
{
var block = PlaceNew(Type, Position);
block.Rotation = Rotation;
block.Color = Color;
block.Material = Material;
block.UniformScale = UniformScale;
block.Scale = Scale;
block.copiedFrom = Id;
return block;
}
private void OnPlacedInit(object sender, BlockPlacedRemovedEventArgs e)
{ //Member method instead of lambda to avoid constantly creating delegates
if (e.ID != Id) return;
Placed -= OnPlacedInit; //And we can reference it
InitData = default; //Remove initializer as it's no longer valid - if the block gets removed it shouldn't be used again
if (copiedFrom != default)
BlockCloneEngine.CopyBlockStats(copiedFrom, Id);
}
public override string ToString()
{
return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Type)}: {Type}, {nameof(Color)}: {Color}, {nameof(Exists)}: {Exists}";
}
public bool Equals(Block other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Id.Equals(other.Id);
}
public bool Equals(EGID other)
{
return Id.Equals(other);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Block) obj);
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
public static void Init()
{
GameEngineManager.AddGameEngine(PlacementEngine);
GameEngineManager.AddGameEngine(MovementEngine);
GameEngineManager.AddGameEngine(RotationEngine);
GameEngineManager.AddGameEngine(RemovalEngine);
GameEngineManager.AddGameEngine(BlockEngine);
GameEngineManager.AddGameEngine(BlockEventsEngine);
GameEngineManager.AddGameEngine(ScalingEngine);
GameEngineManager.AddGameEngine(SignalEngine);
GameEngineManager.AddGameEngine(BlockCloneEngine);
Wire.signalEngine = SignalEngine; // requires same functionality, no need to duplicate the engine
}
}
}

View file

@ -0,0 +1,217 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Gamecraft.Blocks.BlockGroups;
using Svelto.ECS;
using Unity.Mathematics;
using UnityEngine;
using TechbloxModdingAPI.Blocks;
using TechbloxModdingAPI.Blocks.Engines;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI
{
/// <summary>
/// A group of blocks that can be selected together. The placed version of blueprints. Dispose after usage.
/// </summary>
public class BlockGroup : EcsObjectBase, ICollection<Block>, IDisposable
{
internal static BlueprintEngine _engine = new BlueprintEngine();
private readonly Block sourceBlock;
private readonly List<Block> blocks;
private float3 position, rotation;
internal bool PosAndRotCalculated;
internal BlockGroup(int id, Block block) : base(new EGID((uint)id,
BlockGroupExclusiveGroups.BlockGroupEntityGroup))
{
if (id == BlockGroupUtility.GROUP_UNASSIGNED)
throw new BlockException("Cannot create a block group for blocks without a group!");
sourceBlock = block;
blocks = new List<Block>(GetBlocks());
Block.Removed += OnBlockRemoved;
}
private void OnBlockRemoved(object sender, BlockPlacedRemovedEventArgs e)
{
//blocks.RemoveAll(block => block.Id == e.ID); - Allocation heavy
int index = -1;
for (int i = 0; i < blocks.Count; i++)
{
if (blocks[i].Id == e.ID)
{
index = i;
break;
}
}
if (index != -1) blocks.RemoveAt(index);
}
public void Dispose()
{
Block.Removed -= OnBlockRemoved;
}
/// <summary>
/// The position of the block group (center). Can only be used after initialization is complete.
/// </summary>
public float3 Position
{
get
{
if (!PosAndRotCalculated)
Refresh();
return position;
}
set
{
var diff = value - position;
foreach (var block in blocks)
block.Position += diff;
if (!PosAndRotCalculated) //The condition can only be true if a block has been added/removed manually
Refresh(); //So the blocks array is up to date
else
position += diff;
}
}
/// <summary>
/// The rotation of the block group. Can only be used after initialization is complete.
/// </summary>
public float3 Rotation
{
get
{
if (!PosAndRotCalculated)
Refresh();
return rotation;
}
set
{
var diff = value - rotation;
var qdiff = Quaternion.Euler(diff);
foreach (var block in blocks)
{
block.Rotation += diff;
block.Position = qdiff * block.Position;
}
if (!PosAndRotCalculated)
Refresh();
else
rotation += diff;
}
}
/*/// <summary>
/// Removes all of the blocks in this group from the world.
/// </summary>
public void RemoveBlocks()
{
_engine.RemoveBlockGroup(Id); - TODO: Causes a hard crash
}*/
/// <summary>
/// Creates a new block group consisting of a single block.
/// You can add more blocks using the Add() method or by setting the BlockGroup property of the blocks.<br />
/// Note that only newly placed blocks can be added to groups.
/// </summary>
/// <param name="block">The block to add</param>
/// <returns>A new block group containing the given block</returns>
public static BlockGroup Create(Block block)
{
var bg = new BlockGroup(_engine.CreateBlockGroup(block.Position, Quaternion.Euler(block.Rotation)), block);
block.BlockGroup = bg;
return bg;
}
/// <summary>
/// Collects each block that is a part of this group. Also sets the position and rotation.
/// </summary>
/// <returns>An array of blocks</returns>
private Block[] GetBlocks()
{
if (!sourceBlock.Exists) return new[] {sourceBlock}; //The block must exist to get the others
var ret = _engine.GetBlocksFromGroup(sourceBlock.Id, out var pos, out var rot);
position = pos;
rotation = ((Quaternion) rot).eulerAngles;
PosAndRotCalculated = true;
return ret;
}
private void Refresh()
{
blocks.Clear();
blocks.AddRange(GetBlocks());
}
internal static void Init()
{
GameEngineManager.AddGameEngine(_engine);
}
public IEnumerator<Block> GetEnumerator() => blocks.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => blocks.GetEnumerator();
/// <summary>
/// Adds a block to the group. You can only add newly placed blocks
/// so that the game initializes the group membership properly.
/// </summary>
/// <param name="item"></param>
/// <exception cref="NullReferenceException"></exception>
public void Add(Block item)
{
if (item == null) throw new NullReferenceException("Cannot add null to a block group");
item.BlockGroup = this; //Calls AddInternal
}
internal void AddInternal(Block item)
{
blocks.Add(item);
_engine.AddBlockToGroup(item.Id, (int) Id.entityID);
}
/// <summary>
/// Removes all blocks from this group.
/// You cannot remove blocks that have been initialized, only those that you placed recently.
/// </summary>
public void Clear()
{
while (blocks.Count > 0)
Remove(blocks[blocks.Count - 1]);
}
public bool Contains(Block item) => blocks.Contains(item);
public void CopyTo(Block[] array, int arrayIndex) => blocks.CopyTo(array, arrayIndex);
/// <summary>
/// Removes a block from this group.
/// You cannot remove blocks that have been initialized, only those that you placed recently.
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
/// <exception cref="NullReferenceException"></exception>
public bool Remove(Block item)
{
if (item == null) throw new NullReferenceException("Cannot remove null from a block group");
bool ret = item.BlockGroup == this;
if (ret)
item.BlockGroup = null; //Calls RemoveInternal
return ret;
}
internal void RemoveInternal(Block item) => blocks.Remove(item);
public int Count => blocks.Count;
public bool IsReadOnly { get; } = false;
public Block this[int index] => blocks[index]; //Setting is not supported, since the order doesn't matter
public override string ToString()
{
return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Rotation)}: {Rotation}, {nameof(Count)}: {Count}";
}
}
}

View file

@ -0,0 +1,64 @@
using System;
using Unity.Mathematics;
namespace TechbloxModdingAPI.Blocks
{
public struct BlockColor
{
public BlockColors Color => Index == byte.MaxValue
? BlockColors.Default
: (BlockColors) (Index % 10);
public byte Darkness => (byte) (Index == byte.MaxValue
? 0
: Index / 10);
public byte Index { get; }
public BlockColor(byte index)
{
if (index > 99 && index != byte.MaxValue)
throw new ArgumentOutOfRangeException(nameof(index), "Invalid color index. Must be 0-90 or 255.");
Index = index;
}
public BlockColor(BlockColors color, byte darkness = 0)
{
if (darkness > 9)
throw new ArgumentOutOfRangeException(nameof(darkness), "Darkness must be 0-9 where 0 is default.");
if (color > BlockColors.Red && color != BlockColors.Default) //Last valid color
throw new ArgumentOutOfRangeException(nameof(color), "Invalid color!");
Index = (byte) (darkness * 10 + (byte) color);
}
public static implicit operator BlockColor(BlockColors color)
{
return new BlockColor(color);
}
public float4 RGBA => Block.BlockEngine.ConvertBlockColor(Index);
public override string ToString()
{
return $"{nameof(Color)}: {Color}, {nameof(Darkness)}: {Darkness}";
}
}
/// <summary>
/// Preset block colours
/// </summary>
public enum BlockColors : byte
{
Default = byte.MaxValue,
White = 0,
Pink,
Purple,
Blue,
Aqua,
Green,
Lime,
Yellow,
Orange,
Red
}
}

View file

@ -1,10 +1,10 @@
using System;
using GamecraftModdingAPI;
using TechbloxModdingAPI;
namespace GamecraftModdingAPI.Blocks
namespace TechbloxModdingAPI.Blocks
{
public class BlockException : GamecraftModdingAPIException
public class BlockException : TechbloxModdingAPIException
{
public BlockException()
{
@ -40,4 +40,26 @@ namespace GamecraftModdingAPI.Blocks
{
}
}
public class WiringException : BlockException
{
public WiringException()
{
}
public WiringException(string message) : base(message)
{
}
}
public class WireInvalidException : WiringException
{
public WireInvalidException()
{
}
public WireInvalidException(string message) : base(message)
{
}
}
}

View file

@ -0,0 +1,284 @@
namespace TechbloxModdingAPI.Blocks
{
/// <summary>
/// Possible block types
/// </summary>
public enum BlockIDs : ushort
{
/// <summary>
/// Called "nothing" in Techblox. (DBID.NOTHING)
/// </summary>
Invalid = ushort.MaxValue,
Cube = 0,
Wedge,
QuarterPyramid,
Tetrahedron,
RoundedWedge,
RoundedQuarterPyramid,
RoundedTetrahedron,
NegativeQuarterPyramid,
NegativeTetrahedron,
RoundedNegativeQuarterPyramid,
RoundedNegativeTetrahedron,
Plate,
PlateWedge,
PlateQuarterPyramid,
PlateTetrahedron,
Sphere,
CarWheelArch = 47,
CarArchSmallFlare,
CarArchFlare,
CarArchExtrudedFlare,
Axle = 100,
Hinge,
BallJoint,
UniversalJoint,
TelescopicJoint,
DampedHingeSpring,
DampedAxleSpring,
DampedSpring,
WheelRigNoSteering,
WheelRigWithSteering,
PlateTriangle = 130,
PlateCircle,
PlateQuarterCircle,
PlateRoundedWedge,
PlateRoundedTetrahedron,
Cone,
ConeSegment,
DoubleSliced,
HalfDoubleSliced,
EighthPyramid,
Hemisphere,
WideCylinder,
WideCylinderBend,
WideCylinderT,
WideCylinderCross,
WideCylinderCorner,
NarrowCylinder,
NarrowCylinderBend,
NarrowCylinderT,
NarrowCylinderCross,
DriverSeat,
PassengerSeat,
Engine,
NarrowCylinderCorner,
PlateWideCylinder,
PlateNarrowCylinder,
PlateNegativeTetrahedron,
PlateNegativeQuarterPyramid,
PlateRoundedNegativeTetrahedron,
PlateRoundedNegativeQuarterPyramid,
HeadlampSquare,
HeadlampCircle,
HeadlampWedge,
WideCylinderDiagonal,
NarrowCylinderDiagonal,
HeadlampTetrahedron,
GoKartEngine,
Screen5X2Y2Z,
Screen5X2Y3Z,
Screen5X2Y5Z,
Screen9X2Y2Z,
Screen9X3Y2Z,
Screen9X2Y3Z,
Screen9X3Y3Z,
Screen9X2Y5Z,
Screen9X3Y5Z,
Screen11X3Y2Z,
Screen11X3Y3Z,
Screen11X3Y5Z,
Window6X2Y2Z,
Window6X3Y2Z,
Window6X2Y2ZS1,
Window6X3Y2ZS1,
Window6X2Y2ZS2,
Window6X3Y2ZS2,
Window6X2Y2ZS4,
Window6X3Y2ZS4,
FrameSquare,
FrameSkewedSquare,
FrameTriangle,
FrameSkewedTriangle,
GlassFrameSquare,
GlassFrameSkewedSquare,
GlassFrameTriangle,
GlassFrameSkewedTriangle,
GlassPlate,
GlassPlateTriangle,
GoKartWheelRigNoSteering,
GoKartWheelRigWithSteering,
GoKartSeat,
CarWheelWideProfile,
CarWheel,
GoKartWheelWideProfile,
GoKartWheel,
ANDLogicGate,
ORLogicGate,
NOTLogicGate,
NANDLogicGate,
NORLogicGate,
XORLogicGate,
XNORLogicGate,
AdderMathBlock,
SubtractorMathBlock,
MultiplierMathBlock,
DividerMathBlock,
InverterMathBlock,
AverageMathBlock,
AbsoluteMathBlock,
MinMathBlock,
MaxMathBlock,
SimpleConnector,
Motor,
AxleServo,
HingeServo,
Piston,
Button,
Switch,
Dial,
Lever,
ThreeWaySwitch,
EqualsMathBlock,
LessThanMathBlock,
LessThanOrEqualMathBlock,
GreaterThanMathBlock,
GreaterThanOrEqualMathBlock,
HatchbackWheelRigNoSteering,
HatchbackWheelRigWithSteering,
HatchbackEngine,
HatchbackWheel,
HatchbackWheelArch,
HatchbackArchSmallFlare,
HatchbackArchFlare,
CeilingStripLight,
CardboardBox,
BarrierRail,
BarrierRailEnd,
TruckWheel,
HatchbackWheelWideProfile,
TruckWheelRigWithSteering = 249,
TruckWheelRigNoSteering,
HatchbackDriverSeat,
HatchbackPassengerSeat,
FormulaEngine,
SmallGrass,
SmallGrassRoad,
GrassBridge,
SmallGrassTurn,
MediumGrassTurn,
LargeGrassTurn,
ExtraLargeGrassTurn,
TruckWheelDouble,
TruckWheelArch,
TruckArchSingleFlare,
WoodenDoorWithWindow,
TyreBarrierCorner,
TyreBarrierEdge,
TyreBarrierCenter,
AppleTree,
AppleForestTree,
FormulaWheel,
FormulaWheelRear,
AppleSapling,
GrassHill,
GrassHillInnerCorner,
GrassHillOuterCorner,
GrassRoadHill,
FormulaSeat,
SmallDirt,
SmallDirtRoad,
SmallDirtTurn,
MediumDirtTurn,
LargeDirtTurn,
ExtraLargeDirtTurn,
SmallGrid,
MonsterTruckWheel,
SmallGrassGridStart,
SmallGrassRumbleStripRoad,
SmallGrassRumbleStripEndRoad,
SmallGrassStartLine,
MonsterTruckEngine,
DirtHill,
DirtHillInnerCorner,
DirtHillOuterCorner,
BuildingWindowEdge,
BuildingWindowCorner,
BuildingWindowStraight,
BuildingWindowTJunction,
BuildingWindowCross,
BuildingWindowEdgeSill,
BuildingWindowCornerSill,
BuildingWindowTJunctionSill,
Broadleaf,
ForestBroadleaf,
AzaleaBush,
AzaleaFlowers1,
AzaleaFlowers2,
TreeStump1,
TreeStump2,
FieldJuniper,
ForestJuniper,
JuniperSapling,
JuniperSeedling,
FieldRedMaple,
RedMapleForest1,
RedMapleForest2,
RedMapleSapling,
FieldWhiteSpruce,
ForestWhiteSpruce,
WhiteSpruceSapling,
GirderBase,
GirderStraight,
GirderDiagonal,
GirderCorner,
PostBase,
PostStraight,
PostLShape,
PostTJunction,
PostCross,
PostCorner,
PostDiagonal,
DirtRock1,
DirtRock2,
DirtRock3,
DirtRock4,
DirtRoadHill,
WoodenPalette,
ElderberryBush,
BarrelCactus,
KnapweedFlower,
MarigoldFlowers,
TrampledBushyBluestep,
RoughGrass,
DogRose,
WesternSwordFern,
BackyardGrass,
ThickGrass,
FireExtinguisher,
DirtLowRamp,
DirtTabletopRamp,
MonsterTruckWheelRigNoSteering,
MonsterTruckWheelRigWithSteering,
MeadowCloudyDayAtmosphere,
BarrierRailDiagonal,
DirtHighRamp,
GrassRock1,
GrassRock2,
GrassRock3,
GrassRock4,
GreenFieldsSunnyDayAtmosphere,
RedMountainsDawnAtmosphere,
HighFantasySunriseAtmosphere,
/// <summary>
/// The grid block used by the world editor, named Small Grid like the other one
/// </summary>
SmallGridInWorldEditor,
SegoeUITextblock = 376,
GravtracTextblock,
HauserTextblock,
TechnopollasTextblock,
BitBlock = 385,
Timer
}
}

View file

@ -0,0 +1,35 @@
namespace TechbloxModdingAPI.Blocks
{
public enum BlockMaterial : byte
{
Default = byte.MaxValue,
SteelBodywork = 0,
RigidSteel,
CarbonFiber,
Plastic,
Wood = 6,
RigidSteelPainted,
RigidSteelRustedPaint,
RigidSteelHeavyRust,
SteelBodyworkMetallicPaint,
SteelBodyworkRustedPaint,
SteelBodyworkHeavyRust,
WoodVarnishedDark,
Chrome,
FenceChainLink,
ConcreteUnpainted,
Grid9x9,
CeramicTileFloor,
PlasticBumpy,
PlasticDustySmeared,
AluminiumGarageDoor,
SteelRigidScratched,
AluminiumBrushedTinted,
AluminiumSheetStained,
ConcretePaintedGrooves,
PlasticSpecklySatin,
SteelBodyworkPaintedChipped,
WoodPainted,
WoodRoughGrungy,
}
}

View file

@ -0,0 +1,251 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using DataLoader;
using Svelto.Tasks;
using Svelto.Tasks.Enumerators;
using Unity.Mathematics;
using UnityEngine;
using TechbloxModdingAPI.App;
using TechbloxModdingAPI.Tests;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.Blocks
{
#if TEST
/// <summary>
/// Block test cases. Not accessible in release versions.
/// </summary>
[APITestClass]
public static class BlockTests
{
[APITestCase(TestType.Game)] //At least one block must be placed for simulation to work
public static void TestPlaceNew()
{
Block newBlock = Block.PlaceNew(BlockIDs.Cube, float3.zero);
Assert.NotNull(newBlock.Id, "Newly placed block is missing Id. This should be populated when the block is placed.", "Newly placed block Id is not null, block successfully placed.");
}
[APITestCase(TestType.EditMode)]
public static void TestInitProperty()
{
Block newBlock = Block.PlaceNew(BlockIDs.Cube, float3.zero + 2);
if (!Assert.CloseTo(newBlock.Position, (float3.zero + 2), $"Newly placed block at {newBlock.Position} is expected at {Unity.Mathematics.float3.zero + 2}.", "Newly placed block position matches.")) return;
//Assert.Equal(newBlock.Exists, true, "Newly placed block does not exist, possibly because Sync() skipped/missed/failed.", "Newly placed block exists, Sync() successful.");
}
[APITestCase(TestType.EditMode)]
public static void TestBlockIDCoverage()
{
Assert.Equal(
FullGameFields._dataDb.GetValues<CubeListData>().Keys.Select(ushort.Parse).OrderBy(id => id)
.SequenceEqual(Enum.GetValues(typeof(BlockIDs)).Cast<ushort>().OrderBy(id => id)
.Except(new[] {(ushort) BlockIDs.Invalid})), true,
"Block ID enum is different than the known block types, update needed.",
"Block ID enum matches the known block types.");
}
private static Block[] blocks; // Store placed blocks as some blocks are already present as the workshop and the game save
[APITestCase(TestType.EditMode)]
public static void TestBlockIDs()
{
float3 pos = new float3();
var values = Enum.GetValues(typeof(BlockIDs));
blocks = new Block[values.Length - 1]; // Minus the invalid ID
int i = 0;
foreach (BlockIDs id in values)
{
if (id == BlockIDs.Invalid) continue;
try
{
blocks[i++] = Block.PlaceNew(id, pos);
pos += 0.2f;
}
catch (Exception e)
{ //Only print failed case
Assert.Fail($"Failed to place block type {id}: {e}");
return;
}
}
Assert.Pass("Placing all possible block types succeeded.");
}
[APITestCase(TestType.EditMode)]
public static IEnumerator<TaskContract> TestBlockProperties()
{ //Uses the result of the previous test case
yield return Yield.It;
if (blocks is null)
yield break;
for (var index = 0; index < blocks.Length; index++)
{
if (index % 50 == 0) yield return Yield.It; //The material or flipped status can only be changed 130 times per submission
var block = blocks[index];
if (!block.Exists) continue;
foreach (var property in block.GetType().GetProperties())
{
if (property.Name == "Material" || property.Name == "Flipped") continue; // TODO: Crashes in game
if (property.Name == "Material" || property.Name == "Flipped")
{
Console.WriteLine("Block type: "+block.Type);
Console.WriteLine("Will set " + property.Name);
yield return new WaitForSecondsEnumerator(1).Continue();
}
//Includes specialised block properties
if (property.SetMethod == null) continue;
var testValues = new (Type, object, Predicate<object>)[]
{
//(type, default value, predicate or null for equality)
(typeof(long), 3, null),
(typeof(int), 4, null),
(typeof(double), 5.2f, obj => Math.Abs((double) obj - 5.2f) < float.Epsilon),
(typeof(float), 5.2f, obj => Math.Abs((float) obj - 5.2f) < float.Epsilon),
(typeof(bool), true, obj => (bool) obj),
(typeof(string), "Test", obj => (string) obj == "Test"), //String equality check
(typeof(float3), (float3) 2, obj => math.all((float3) obj - 2 < (float3) float.Epsilon)),
(typeof(BlockColor), new BlockColor(BlockColors.Aqua, 2), null),
(typeof(float4), (float4) 5, obj => math.all((float4) obj - 5 < (float4) float.Epsilon))
};
var propType = property.PropertyType;
if (!propType.IsValueType) continue;
(object valueToUse, Predicate<object> predicateToUse) = (null, null);
foreach (var (type, value, predicate) in testValues)
{
if (type.IsAssignableFrom(propType))
{
valueToUse = value;
predicateToUse = predicate ?? (obj => Equals(obj, value));
break;
}
}
if (propType.IsEnum)
{
var values = propType.GetEnumValues();
valueToUse = values.GetValue(values.Length / 2);
predicateToUse = val => Equals(val, valueToUse);
}
if (valueToUse == null)
{
Assert.Fail($"Property {block.GetType().Name}.{property.Name} has an unknown type {propType}, test needs fixing.");
yield break;
}
try
{
property.SetValue(block, valueToUse);
}
catch (Exception e)
{
Assert.Fail($"Failed to set property {block.GetType().Name}.{property.Name} to {valueToUse}\n{e}");
}
object got;
try
{
got = property.GetValue(block);
}
catch (Exception e)
{
Assert.Fail($"Failed to get property {block.GetType().Name}.{property.Name}\n{e}");
continue;
}
var attr = property.GetCustomAttribute<TestValueAttribute>();
if (!predicateToUse(got) && (attr == null || !Equals(attr.PossibleValue, got)))
{
Assert.Fail($"Property {block.GetType().Name}.{property.Name} value {got} does not equal {valueToUse} for block {block}.");
yield break;
}
}
}
Assert.Pass("Setting all possible properties of all registered API block types succeeded.");
}
[APITestCase(TestType.EditMode)]
public static IEnumerator<TaskContract> TestDefaultValue()
{
for (int i = 0; i < 2; i++)
{ //Tests shared defaults
var block = Block.PlaceNew(BlockIDs.Cube, 1);
while (!block.Exists)
yield return Yield.It;
block.Remove();
while (block.Exists)
yield return Yield.It;
if(!Assert.Equal(block.Position, default,
$"Block position default value {block.Position} is incorrect, should be 0.",
$"Block position default value {block.Position} matches default."))
yield break;
block.Position = 4;
}
}
[APITestCase(TestType.EditMode)]
public static void TestDampedSpring()
{
Block newBlock = Block.PlaceNew(BlockIDs.DampedSpring, Unity.Mathematics.float3.zero + 1);
DampedSpring b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler
Assert.Errorless(() => { b = (DampedSpring) newBlock; }, "Casting block to DampedSpring raised an exception: ", "Casting block to DampedSpring completed without issue.");
if (!Assert.CloseTo(b.Stiffness, 1f, $"DampedSpring.Stiffness {b.Stiffness} does not equal default value, possibly because it failed silently.", "DampedSpring.Stiffness is close enough to default.")) return;
if (!Assert.CloseTo(b.Damping, 0.1f, $"DampedSpring.Damping {b.Damping} does not equal default value, possibly because it failed silently.", "DampedSpring.Damping is close enough to default.")) return;
if (!Assert.CloseTo(b.MaxExtension, 0.3f, $"DampedSpring.MaxExtension {b.MaxExtension} does not equal default value, possibly because it failed silently.", "DampedSpring.MaxExtension is close enough to default.")) return;
}
/*[APITestCase(TestType.Game)]
public static void TestMusicBlock1()
{
Block newBlock = Block.PlaceNew(BlockIDs.MusicBlock, Unity.Mathematics.float3.zero + 2);
MusicBlock b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler
Assert.Errorless(() => { b = newBlock.Specialise<MusicBlock>(); }, "Block.Specialize<MusicBlock>() raised an exception: ", "Block.Specialize<MusicBlock>() completed without issue.");
if (!Assert.NotNull(b, "Block.Specialize<MusicBlock>() returned null, possibly because it failed silently.", "Specialized MusicBlock is not null.")) return;
if (!Assert.CloseTo(b.Volume, 100f, $"MusicBlock.Volume {b.Volume} does not equal default value, possibly because it failed silently.", "MusicBlock.Volume is close enough to default.")) return;
if (!Assert.Equal(b.TrackIndex, 0, $"MusicBlock.TrackIndex {b.TrackIndex} does not equal default value, possibly because it failed silently.", "MusicBlock.TrackIndex is equal to default.")) return;
_musicBlock = b;
}
private static MusicBlock _musicBlock;
[APITestCase(TestType.EditMode)]
public static void TestMusicBlock2()
{
//Block newBlock = Block.GetLastPlacedBlock();
var b = _musicBlock;
if (!Assert.NotNull(b, "Block.Specialize<MusicBlock>() returned null, possibly because it failed silently.", "Specialized MusicBlock is not null.")) return;
b.IsPlaying = true; // play sfx
if (!Assert.Equal(b.IsPlaying, true, $"MusicBlock.IsPlaying {b.IsPlaying} does not equal true, possibly because it failed silently.", "MusicBlock.IsPlaying is set properly.")) return;
if (!Assert.Equal(b.ChannelType, ChannelType.None, $"MusicBlock.ChannelType {b.ChannelType} does not equal default value, possibly because it failed silently.", "MusicBlock.ChannelType is equal to default.")) return;
//Assert.Log(b.Track.ToString());
if (!Assert.Equal(b.Track.ToString(), new Guid("3237ff8f-f5f2-4f84-8144-496ca280f8c0").ToString(), $"MusicBlock.Track {b.Track} does not equal default value, possibly because it failed silently.", "MusicBlock.Track is equal to default.")) return;
}
[APITestCase(TestType.EditMode)]
public static void TestLogicGate()
{
Block newBlock = Block.PlaceNew(BlockIDs.NOTLogicBlock, Unity.Mathematics.float3.zero + 1);
LogicGate b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler
Assert.Errorless(() => { b = newBlock.Specialise<LogicGate>(); }, "Block.Specialize<LogicGate>() raised an exception: ", "Block.Specialize<LogicGate>() completed without issue.");
if (!Assert.NotNull(b, "Block.Specialize<LogicGate>() returned null, possibly because it failed silently.", "Specialized LogicGate is not null.")) return;
if (!Assert.Equal(b.InputCount, 1u, $"LogicGate.InputCount {b.InputCount} does not equal default value, possibly because it failed silently.", "LogicGate.InputCount is default.")) return;
if (!Assert.Equal(b.OutputCount, 1u, $"LogicGate.OutputCount {b.OutputCount} does not equal default value, possibly because it failed silently.", "LogicGate.OutputCount is default.")) return;
if (!Assert.NotNull(b, "Block.Specialize<LogicGate>() returned null, possibly because it failed silently.", "Specialized LogicGate is not null.")) return;
//if (!Assert.Equal(b.PortName(0, true), "Input", $"LogicGate.PortName(0, input:true) {b.PortName(0, true)} does not equal default value, possibly because it failed silently.", "LogicGate.PortName(0, input:true) is close enough to default.")) return;
LogicGate target = null;
if (!Assert.Errorless(() => { target = Block.PlaceNew<LogicGate>(BlockIDs.ANDLogicBlock, Unity.Mathematics.float3.zero + 2); })) return;
Wire newWire = null;
if (!Assert.Errorless(() => { newWire = b.Connect(0, target, 0);})) return;
if (!Assert.NotNull(newWire, "SignalingBlock.Connect(...) returned null, possible because it failed silently.", "SignalingBlock.Connect(...) returned a non-null value.")) return;
}*/
/*[APITestCase(TestType.EditMode)]
public static void TestSpecialiseError()
{
Block newBlock = Block.PlaceNew(BlockIDs.Bench, new float3(1, 1, 1));
if (Assert.Errorful<BlockTypeException>(() => newBlock.Specialise<MusicBlock>(), "Block.Specialise<MusicBlock>() was expected to error on a bench block.", "Block.Specialise<MusicBlock>() errored as expected for a bench block.")) return;
}*/
}
#endif
}

View file

@ -0,0 +1,71 @@
namespace TechbloxModdingAPI.Blocks
{
using RobocraftX.Common;
using Svelto.ECS;
public class DampedSpring : SignalingBlock
{
/// <summary>
/// Constructs a(n) DampedSpring object representing an existing block.
/// </summary>
public DampedSpring(EGID egid) :
base(egid)
{
}
/// <summary>
/// Constructs a(n) DampedSpring object representing an existing block.
/// </summary>
public DampedSpring(uint id) :
base(new EGID(id, CommonExclusiveGroups.DAMPEDSPRING_BLOCK_GROUP))
{
}
/// <summary>
/// Gets or sets the DampedSpring's Stiffness property. Tweakable stat.
/// </summary>
public float Stiffness
{
get
{
return BlockEngine.GetBlockInfo<RobocraftX.Blocks.TweakableJointDampingComponent>(this).stiffness;
}
set
{
BlockEngine.GetBlockInfo<RobocraftX.Blocks.TweakableJointDampingComponent>(this).stiffness = value;
}
}
/// <summary>
/// Gets or sets the DampedSpring's Damping property. Tweakable stat.
/// </summary>
public float Damping
{
get
{
return BlockEngine.GetBlockInfo<RobocraftX.Blocks.TweakableJointDampingComponent>(this).damping;
}
set
{
BlockEngine.GetBlockInfo<RobocraftX.Blocks.TweakableJointDampingComponent>(this).damping = value;
}
}
/// <summary>
/// Gets or sets the DampedSpring's MaxExtension property. Tweakable stat.
/// </summary>
public float MaxExtension
{
get
{
return BlockEngine.GetBlockInfo<RobocraftX.Blocks.DampedSpringReadOnlyStruct>(this).maxExtent;
}
set
{
BlockEngine.GetBlockInfo<RobocraftX.Blocks.DampedSpringReadOnlyStruct>(this).maxExtent = value;
}
}
}
}

View file

@ -0,0 +1,383 @@
namespace TechbloxModdingAPI.Blocks
{
using RobocraftX.Common;
using Svelto.ECS;
public class Engine : SignalingBlock
{
/// <summary>
/// Constructs a(n) Engine object representing an existing block.
/// </summary>
public Engine(EGID egid) :
base(egid)
{
}
/// <summary>
/// Constructs a(n) Engine object representing an existing block.
/// </summary>
public Engine(uint id) :
base(new EGID(id, CommonExclusiveGroups.ENGINE_BLOCK_BUILD_GROUP))
{
}
/*
/// <summary>
/// Gets or sets the Engine's On property. May not be saved.
/// </summary>
public bool On
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).engineOn;
}
set
{
Techblox.BlockColours.BlockColoursCompositionRoot
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).engineOn = value;
}
}
/// <summary>
/// Gets or sets the Engine's CurrentGear property. May not be saved.
/// </summary>
public int CurrentGear
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentGear;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentGear = value;
}
}
/// <summary>
/// Gets or sets the Engine's GearChangeCountdown property. May not be saved.
/// </summary>
public float GearChangeCountdown
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).gearChangeCountdown;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).gearChangeCountdown = value;
}
}
/// <summary>
/// Gets or sets the Engine's CurrentRpmAV property. May not be saved.
/// </summary>
public float CurrentRpmAV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentRpmAV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentRpmAV = value;
}
}
/// <summary>
/// Gets or sets the Engine's CurrentRpmLV property. May not be saved.
/// </summary>
public float CurrentRpmLV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentRpmLV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentRpmLV = value;
}
}
/// <summary>
/// Gets or sets the Engine's TargetRpmAV property. May not be saved.
/// </summary>
public float TargetRpmAV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).targetRpmAV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).targetRpmAV = value;
}
}
/// <summary>
/// Gets or sets the Engine's TargetRpmLV property. May not be saved.
/// </summary>
public float TargetRpmLV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).targetRpmLV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).targetRpmLV = value;
}
}
/// <summary>
/// Gets or sets the Engine's CurrentTorque property. May not be saved.
/// </summary>
public float CurrentTorque
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentTorque;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentTorque = value;
}
}
/// <summary>
/// Gets or sets the Engine's TotalWheelVelocityAV property. May not be saved.
/// </summary>
public float TotalWheelVelocityAV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelVelocityAV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelVelocityAV = value;
}
}
/// <summary>
/// Gets or sets the Engine's TotalWheelVelocityLV property. May not be saved.
/// </summary>
public float TotalWheelVelocityLV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelVelocityLV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelVelocityLV = value;
}
}
/// <summary>
/// Gets or sets the Engine's TotalWheelCount property. May not be saved.
/// </summary>
public int TotalWheelCount
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelCount;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelCount = value;
}
}
/// <summary>
/// Gets or sets the Engine's LastGearUpInput property. May not be saved.
/// </summary>
public bool LastGearUpInput
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).lastGearUpInput;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).lastGearUpInput = value;
}
}
/// <summary>
/// Gets or sets the Engine's LastGearDownInput property. May not be saved.
/// </summary>
public bool LastGearDownInput
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).lastGearDownInput;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).lastGearDownInput = value;
}
}
/// <summary>
/// Gets or sets the Engine's ManualToAutoGearCoolOffCounter property. May not be saved.
/// </summary>
public float ManualToAutoGearCoolOffCounter
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).manualToAutoGearCoolOffCounter;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).manualToAutoGearCoolOffCounter = value;
}
}
/// <summary>
/// Gets or sets the Engine's Load property. May not be saved.
/// </summary>
public float Load
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).load;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).load = value;
}
}
/// <summary>
/// Gets or sets the Engine's Power property. Tweakable stat.
/// </summary>
public float Power
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockTweakableComponent>(this).power;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockTweakableComponent>(this).power = value;
}
}
/// <summary>
/// Gets or sets the Engine's AutomaticGears property. Tweakable stat.
/// </summary>
public bool AutomaticGears
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockTweakableComponent>(this).automaticGears;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockTweakableComponent>(this).automaticGears = value;
}
}
/// <summary>
/// Gets or sets the Engine's GearChangeTime property. May not be saved.
/// </summary>
public float GearChangeTime
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).gearChangeTime;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).gearChangeTime = value;
}
}
/// <summary>
/// Gets or sets the Engine's MinRpm property. May not be saved.
/// </summary>
public float MinRpm
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).minRpm;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).minRpm = value;
}
}
/// <summary>
/// Gets or sets the Engine's MaxRpm property. May not be saved.
/// </summary>
public float MaxRpm
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).maxRpm;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).maxRpm = value;
}
}
/// <summary>
/// Gets the Engine's GearDownRpms property. May not be saved.
/// </summary>
public float[] GearDownRpms
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).gearDownRpms.ToManagedArray<float>();
}
}
/// <summary>
/// Gets or sets the Engine's GearUpRpm property. May not be saved.
/// </summary>
public float GearUpRpm
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).gearUpRpm;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).gearUpRpm = value;
}
}
/// <summary>
/// Gets or sets the Engine's MaxRpmChange property. May not be saved.
/// </summary>
public float MaxRpmChange
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).maxRpmChange;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).maxRpmChange = value;
}
}
/// <summary>
/// Gets or sets the Engine's ManualToAutoGearCoolOffTime property. May not be saved.
/// </summary>
public float ManualToAutoGearCoolOffTime
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).manualToAutoGearCoolOffTime;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockReadonlyComponent>(this).manualToAutoGearCoolOffTime = value;
}
}*/
}
}

View file

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Gamecraft.Wires;
using HarmonyLib;
using RobocraftX.Blocks;
using RobocraftX.Character;
using RobocraftX.Common;
using Svelto.DataStructures;
using Svelto.ECS;
using TechbloxModdingAPI.Engines;
namespace TechbloxModdingAPI.Blocks.Engines
{
public class BlockCloneEngine : IApiEngine
{
private static Type copyEngineType =
AccessTools.TypeByName("Gamecraft.GUI.Tweaks.Engines.CopyTweaksOnPickEngine");
private static Type copyWireEngineType =
AccessTools.TypeByName("Gamecraft.Wires.WireConnectionCopyOnPickEngine");
private static Type createWireEngineType =
AccessTools.TypeByName("RobocraftX.GUI.Wires.WireConnectionCreateOnPlaceEngine");
private MethodBase copyFromBlock = AccessTools.Method(copyEngineType, "CopyTweaksFromBlock");
private MethodBase copyToBlock = AccessTools.Method(copyEngineType, "ApplyTweaksToPlacedBlock");
private MethodBase copyWireFromBlock = AccessTools.Method(copyWireEngineType, "CopyWireInputsAndOutputs");
private MethodBase copyWireToBlock = AccessTools.Method(createWireEngineType, "PlaceWiresOnPlaceNewCube");
public void Ready()
{
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
}
public void CopyBlockStats(EGID sourceID, EGID targetID)
{
var allCharacters = (LocalFasterReadOnlyList<ExclusiveGroupStruct>) CharacterExclusiveGroups.AllCharacters;
foreach (var ((pickedBlockColl, count), _) in entitiesDB.QueryEntities<PickedBlockExtraDataStruct>(allCharacters))
{
for (int i = 0; i < count; ++i)
{
ref PickedBlockExtraDataStruct pickedBlock = ref pickedBlockColl[i];
var oldStruct = pickedBlock;
pickedBlock.pickedBlockEntityID = sourceID;
pickedBlock.placedBlockEntityID = targetID;
pickedBlock.placedBlockTweaksMustCopy = true;
if (entitiesDB.Exists<DBEntityStruct>(pickedBlock.pickedBlockEntityID)
&& entitiesDB.Exists<DBEntityStruct>(pickedBlock.placedBlockEntityID))
{
copyFromBlock.Invoke(Patch.copyEngine, new object[] {pickedBlock.ID, pickedBlock});
uint playerID = Player.LocalPlayer.Id;
var parameters = new object[] {playerID, pickedBlock};
copyWireFromBlock.Invoke(Patch.copyWireEngine, parameters);
pickedBlock = (PickedBlockExtraDataStruct) parameters[1]; //ref arg
copyToBlock.Invoke(Patch.copyEngine, new object[] {pickedBlock.ID, pickedBlock});
ExclusiveGroupStruct group = BuildModeWiresGroups.WIRES_COPY_GROUP + playerID;
copyWireToBlock.Invoke(Patch.createWireEngine, new object[] {group, pickedBlock.ID});
pickedBlock.placedBlockTweaksMustCopy = false;
}
pickedBlock = oldStruct; //Make sure to not interfere with the game - Although that might not be the case with the wire copying
}
}
}
[HarmonyPatch]
private static class Patch
{
public static object copyEngine;
public static object copyWireEngine;
public static object createWireEngine;
public static void Postfix(object __instance)
{
if (__instance.GetType() == copyEngineType)
copyEngine = __instance;
else if (__instance.GetType() == copyWireEngineType)
copyWireEngine = __instance;
else if (__instance.GetType() == createWireEngineType)
createWireEngine = __instance;
}
public static IEnumerable<MethodBase> TargetMethods()
{
return new[]
{
AccessTools.GetDeclaredConstructors(copyEngineType)[0],
AccessTools.GetDeclaredConstructors(copyWireEngineType)[0],
AccessTools.GetDeclaredConstructors(createWireEngineType)[0]
};
}
}
public string Name { get; } = "TechbloxModdingAPIBlockCloneGameEngine";
public bool isRemovable { get; } = false;
}
}

View file

@ -0,0 +1,274 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using HarmonyLib;
using Gamecraft.ColourPalette;
using Gamecraft.TimeRunning;
using Gamecraft.Wires;
using RobocraftX.Blocks;
using RobocraftX.Common;
using RobocraftX.Physics;
using RobocraftX.Rendering;
using RobocraftX.Rendering.GPUI;
using Svelto.DataStructures;
using Svelto.ECS;
using Svelto.ECS.Hybrid;
using Techblox.BuildingDrone;
using Unity.Mathematics;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.Blocks.Engines
{
/// <summary>
/// Engine for executing general block actions
/// </summary>
public partial class BlockEngine : IApiEngine
{
public string Name { get; } = "TechbloxModdingAPIBlockGameEngine";
public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => false;
public void Dispose()
{
}
public void Ready()
{
}
public Block[] GetConnectedBlocks(EGID blockID)
{
if (!BlockExists(blockID)) return new Block[0];
Stack<EGID> cubeStack = new Stack<EGID>();
FasterList<EGID> cubes = new FasterList<EGID>(10);
var coll = entitiesDB.QueryEntities<GridConnectionsEntityStruct>();
foreach (var (ecoll, _) in coll)
{
var ecollB = ecoll.ToBuffer();
for(int i = 0; i < ecoll.count; i++)
{
ref var conn = ref ecollB.buffer[i];
conn.isProcessed = false;
}
}
ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubes,
(in GridConnectionsEntityStruct g) => { return false; });
var ret = new Block[cubes.count];
for (int i = 0; i < cubes.count; i++)
ret[i] = Block.New(cubes[i]);
return ret;
}
public float4 ConvertBlockColor(byte index) => index == byte.MaxValue
? new float4(-1f, -1f, -1f, -1f)
: entitiesDB.QueryEntity<PaletteEntryEntityStruct>(index,
CommonExclusiveGroups.COLOUR_PALETTE_GROUP).Colour;
public OptionalRef<T> GetBlockInfoOptional<T>(Block block) where T : unmanaged, IEntityComponent
{
return entitiesDB.QueryEntityOptional<T>(block);
}
public ref T GetBlockInfo<T>(Block block) where T : unmanaged, IEntityComponent
{
return ref entitiesDB.QueryEntityOrDefault<T>(block);
}
internal ref T GetBlockInfo<T>(EcsObjectBase obj) where T : unmanaged, IEntityComponent
{
return ref entitiesDB.QueryEntityOrDefault<T>(obj);
}
public ref T GetBlockInfoViewComponent<T>(Block block) where T : struct, IEntityViewComponent
{
return ref entitiesDB.QueryEntityOrDefault<T>(block);
}
public void UpdateDisplayedBlock(EGID id)
{
if (!BlockExists(id)) return;
RenderingPatch.UpdateBlocks();
}
internal void UpdatePrefab(Block block, byte material, bool flipped)
{
var prefabAssetIDOpt = entitiesDB.QueryEntityOptional<PrefabAssetIDComponent>(block);
uint prefabAssetID = prefabAssetIDOpt
? prefabAssetIDOpt.Get().prefabAssetID
: uint.MaxValue;
if (prefabAssetID == uint.MaxValue)
{
if (entitiesDB.QueryEntityOptional<DBEntityStruct>(block)) //The block exists
throw new BlockException("Prefab asset ID not found for block " + block); //Set by the game
return;
}
uint prefabId =
PrefabsID.GetOrCreatePrefabID((ushort) prefabAssetID, material, 1, flipped);
entitiesDB.QueryEntityOrDefault<GFXPrefabEntityStructGPUI>(block).prefabID = prefabId;
if (block.Exists)
{
entitiesDB.PublishEntityChange<CubeMaterialStruct>(block.Id);
entitiesDB.PublishEntityChange<GFXPrefabEntityStructGPUI>(block.Id);
ref BuildingActionComponent local =
ref entitiesDB.QueryEntity<BuildingActionComponent>(BuildingDroneUtility
.GetLocalBuildingDrone(entitiesDB).ToEGID(entitiesDB));
local.buildAction = BuildAction.ChangeMaterial;
local.targetPosition = block.Position;
this.entitiesDB.PublishEntityChange<BuildingActionComponent>(local.ID);
}
//Phyiscs prefab: prefabAssetID, set on block creation from the CubeListData
}
public bool BlockExists(EGID blockID)
{
return entitiesDB.Exists<DBEntityStruct>(blockID);
}
public SimBody[] GetSimBodiesFromID(byte id)
{
var ret = new FasterList<SimBody>(4);
var oide = entitiesDB.QueryEntities<ObjectIdEntityStruct>();
EGIDMapper<GridConnectionsEntityStruct>? connections = null;
foreach (var ((oids, count), _) in oide)
{
for (int i = 0; i < count; i++)
{
ref ObjectIdEntityStruct oid = ref oids[i];
if (oid.objectId != id) continue;
if (!connections.HasValue) //Would need reflection to get the group from the build group otherwise
connections = entitiesDB.QueryMappedEntities<GridConnectionsEntityStruct>(oid.ID.groupID);
var rid = connections.Value.Entity(oid.ID.entityID).machineRigidBodyId;
foreach (var rb in ret)
{
if (rb.Id.entityID == rid)
goto DUPLICATE; //Multiple Object Identifiers on one rigid body
}
ret.Add(new SimBody(rid));
DUPLICATE: ;
}
}
return ret.ToArray();
}
public SimBody[] GetConnectedSimBodies(uint id)
{
var joints = entitiesDB.QueryEntities<JointEntityStruct>(MachineSimulationGroups.JOINTS_GROUP).ToBuffer();
var list = new FasterList<SimBody>(4);
for (int i = 0; i < joints.count; i++)
{
ref var joint = ref joints.buffer[i];
if (joint.isBroken) continue;
if (joint.connectedEntityA == id) list.Add(new SimBody(joint.connectedEntityB));
else if (joint.connectedEntityB == id) list.Add(new SimBody(joint.connectedEntityA));
}
return list.ToArray();
}
public SimBody[] GetClusterBodies(uint cid)
{
var groups = entitiesDB.QueryEntities<GridConnectionsEntityStruct>();
var bodies = new HashSet<uint>();
foreach (var (coll, _) in groups)
{
var array = coll.ToBuffer().buffer;
for (var index = 0; index < array.capacity; index++)
{
var conn = array[index];
if (conn.clusterId == cid)
bodies.Add(conn.machineRigidBodyId);
}
}
return bodies.Select(id => new SimBody(id, cid)).ToArray();
}
public EGID? FindBlockEGID(uint id)
{
var groups = entitiesDB.FindGroups<DBEntityStruct>();
foreach (ExclusiveGroupStruct group in groups)
{
if (entitiesDB.Exists<DBEntityStruct>(id, group))
return new EGID(id, group);
}
return null;
}
public Cluster GetCluster(uint sbid)
{
var groups = entitiesDB.QueryEntities<GridConnectionsEntityStruct>();
foreach (var (coll, _) in groups)
{
var array = coll.ToBuffer().buffer;
for (var index = 0; index < array.capacity; index++)
{
var conn = array[index];
//Static blocks don't have a cluster ID but the cluster destruction manager should have one
if (conn.machineRigidBodyId == sbid && conn.clusterId != uint.MaxValue)
return new Cluster(conn.clusterId);
}
}
return null;
}
public Block[] GetBodyBlocks(uint sbid)
{
var groups = entitiesDB.QueryEntities<GridConnectionsEntityStruct>();
var set = new HashSet<Block>();
foreach (var (coll, _) in groups)
{
var array = coll.ToBuffer().buffer;
for (var index = 0; index < array.capacity; index++)
{
var conn = array[index];
if (conn.machineRigidBodyId == sbid)
set.Add(Block.New(conn.ID));
}
}
return set.ToArray();
}
#if DEBUG
public EntitiesDB GetEntitiesDB()
{
return entitiesDB;
}
#endif
[HarmonyPatch]
public static class RenderingPatch
{
private static ComputeRenderingEntitiesMatricesEngine Engine;
public static void Postfix(ComputeRenderingEntitiesMatricesEngine __instance)
{
Engine = __instance;
}
public static MethodBase TargetMethod()
{
return typeof(ComputeRenderingEntitiesMatricesEngine).GetConstructors()[0];
}
public static void UpdateBlocks()
{
var data = new RenderingDataStruct();
Engine.Add(ref data, new EGID(0, CommonExclusiveGroups.BUTTON_BLOCK_GROUP));
}
}
}
}

View file

@ -0,0 +1,52 @@
using System;
using RobocraftX.Blocks;
using Svelto.ECS;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.Blocks.Engines
{
public class BlockEventsEngine : IReactionaryEngine<BlockTagEntityStruct>
{
public WrappedHandler<BlockPlacedRemovedEventArgs> Placed;
public WrappedHandler<BlockPlacedRemovedEventArgs> Removed;
public void Ready()
{
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
}
public string Name { get; } = "TechbloxModdingAPIBlockEventsEngine";
public bool isRemovable { get; } = false;
private bool shouldAddRemove;
public void Add(ref BlockTagEntityStruct entityComponent, EGID egid)
{
if (!(shouldAddRemove = !shouldAddRemove))
return;
Placed.Invoke(this, new BlockPlacedRemovedEventArgs {ID = egid});
}
public void Remove(ref BlockTagEntityStruct entityComponent, EGID egid)
{
if (!(shouldAddRemove = !shouldAddRemove))
return;
Removed.Invoke(this, new BlockPlacedRemovedEventArgs {ID = egid});
}
}
public struct BlockPlacedRemovedEventArgs
{
public EGID ID;
private Block block;
public Block Block => block ??= Block.New(ID);
}
}

View file

@ -0,0 +1,401 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Gamecraft.Blocks.BlockGroups;
using Gamecraft.GUI.Blueprints;
using HarmonyLib;
using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Common;
using RobocraftX.CR.MachineEditing.BoxSelect;
using RobocraftX.CR.MachineEditing.BoxSelect.ClipboardOperations;
using RobocraftX.Physics;
using RobocraftX.Rendering;
using RobocraftX.Rendering.GPUI;
using Svelto.DataStructures;
using Svelto.ECS;
using Svelto.ECS.DataStructures;
using Svelto.ECS.EntityStructs;
using Svelto.ECS.Native;
using Svelto.ECS.Serialization;
using Techblox.Blocks;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine;
using Allocator = Svelto.Common.Allocator;
namespace TechbloxModdingAPI.Blocks.Engines
{
public class BlueprintEngine : IFactoryEngine
{
private readonly MethodInfo getBlocksFromGroup =
AccessTools.Method("RobocraftX.CR.MachineEditing.PlaceBlockUtility:GetBlocksSharingBlockgroup");
private NativeDynamicArray selectedBlocksInGroup;
private NativeHashSet<ulong> removedConnections = new NativeHashSet<ulong>();
private int addingToBlockGroup = -1;
private static readonly Type PlaceBlueprintUtilityType =
AccessTools.TypeByName("RobocraftX.CR.MachineEditing.PlaceBlueprintUtility");
private static readonly FieldInfo LocalBlockMap =
AccessTools.DeclaredField(PlaceBlueprintUtilityType, "_localBlockMap");
private static readonly MethodInfo BuildBlock = AccessTools.Method(PlaceBlueprintUtilityType, "BuildBlock");
private static readonly MethodInfo BuildWires = AccessTools.Method(PlaceBlueprintUtilityType, "BuildWires");
private static readonly Type SerializeGhostBlueprintType =
AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BoxSelect.SerializeGhostChildrenOnAddEngine");
private static readonly MethodInfo SerializeGhostBlueprint =
AccessTools.Method(SerializeGhostBlueprintType, "SerializeClipboardGhostEntities");
private static NativeEntityRemove nativeRemove;
private static MachineGraphConnectionEntityFactory connectionFactory;
private static IEntityFunctions entityFunctions;
private static ClipboardSerializationDataResourceManager clipboardManager;
private static IEntitySerialization entitySerialization;
private static IEntityFactory entityFactory;
private static FasterList<EGID> globalBlockMap;
private static object SerializeGhostBlueprintInstance;
private static GhostChildEntityFactory BuildGhostBlueprintFactory;
public void Ready()
{
selectedBlocksInGroup = NativeDynamicArray.Alloc<EGID>(Allocator.Persistent);
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
selectedBlocksInGroup.Dispose();
}
public Block[] GetBlocksFromGroup(EGID blockID, out float3 pos, out quaternion rot)
{
var blockPos = default(float3);
var blockRot = default(quaternion);
var parameters = new object[] {blockID, selectedBlocksInGroup, entitiesDB, blockPos, blockRot};
getBlocksFromGroup.Invoke(null, parameters);
pos = (float3) parameters[3];
rot = (quaternion) parameters[4];
int count = selectedBlocksInGroup.Count<EGID>();
var ret = new Block[count];
for (uint i = 0; i < count; i++)
ret[i] = Block.New(selectedBlocksInGroup.Get<EGID>(i));
selectedBlocksInGroup.FastClear();
return ret;
}
public void RemoveBlockGroup(int id)
{
BlockGroupUtility.RemoveAllBlocksInBlockGroup(id, entitiesDB, removedConnections, nativeRemove,
connectionFactory, default).Complete();
}
public int CreateBlockGroup(float3 position, quaternion rotation)
{
int nextFilterId = BlockGroupUtility.NextFilterId;
Factory.BuildEntity<BlockGroupEntityDescriptor>((uint) nextFilterId,
BlockGroupExclusiveGroups.BlockGroupEntityGroup).Init(new BlockGroupTransformEntityComponent
{
blockGroupGridRotation = rotation,
blockGroupGridPosition = position
});
return nextFilterId;
}
public void AddBlockToGroup(EGID blockID, int groupID)
{
if (globalBlockMap == null)
globalBlockMap = FullGameFields._deserialisedBlockMap;
if (groupID != addingToBlockGroup)
{
Logging.MetaDebugLog("Changing current block group from " + addingToBlockGroup + " to " + groupID);
addingToBlockGroup = groupID;
globalBlockMap.Clear();
}
globalBlockMap.Add(blockID);
}
public void SelectBlueprint(uint resourceID)
{
if (resourceID == uint.MaxValue)
BlueprintUtil.UnselectBlueprint(entitiesDB);
else
BlueprintUtil.SelectBlueprint(entitiesDB, resourceID, false, -1);
}
public uint CreateBlueprint()
{
uint index = clipboardManager.AllocateSerializationData();
return index;
}
public void ReplaceBlueprint(uint playerID, uint blueprintID, ICollection<Block> selected, float3 pos, quaternion rot)
{
var blockIDs = new EGID[selected.Count];
using (var enumerator = selected.GetEnumerator())
{
for (var i = 0; enumerator.MoveNext(); i++)
{
var block = enumerator.Current;
blockIDs[i] = block.Id;
}
}
var serializationData = clipboardManager.GetSerializationData(blueprintID);
SelectionSerializationUtility.ClearClipboard(playerID, entitiesDB, entityFunctions, serializationData.blueprintData, -1);
if (selected.Count == 0)
return;
//ref BlockGroupTransformEntityComponent groupTransform = ref EntityNativeDBExtensions.QueryEntity<BlockGroupTransformEntityComponent>(entitiesDb, (uint) local1.currentBlockGroup, BlockGroupExclusiveGroups.BlockGroupEntityGroup);
//ref ColliderAabb collider = ref EntityNativeDBExtensions.QueryEntity<ColliderAabb>(entitiesDB, (uint) groupID, BlockGroupExclusiveGroups.BlockGroupEntityGroup);
//float3 bottomOffset = PlaceBlockUtility.GetBottomOffset(collider);
//var rootPosition = math.mul(groupTransform.blockGroupGridRotation, bottomOffset) + groupTransform.blockGroupGridPosition;
//var rootRotation = groupTransform.blockGroupGridRotation;
clipboardManager.SetGhostSerialized(blueprintID, false);
SelectionSerializationUtility.CopySelectionToClipboard(playerID, entitiesDB,
serializationData.blueprintData, entitySerialization, entityFactory, blockIDs,
(uint) blockIDs.Length, pos, rot, -1);
BuildGhostBlueprint(selected, pos, rot, playerID);
SerializeGhostBlueprint.Invoke(SerializeGhostBlueprintInstance, new object[] {playerID, blueprintID});
}
private void BuildGhostBlueprint(ICollection<Block> blocks, float3 pos, quaternion rot, uint playerID)
{
GhostChildUtility.ClearGhostChildren(playerID, entitiesDB, entityFunctions);
var bssesopt = entitiesDB.QueryEntityOptional<BoxSelectStateEntityStruct>(new EGID(playerID,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup));
if (!bssesopt)
return;
foreach (var block in blocks)
{
GhostChildUtility.BuildGhostChild(in playerID, block.Id, in pos, in rot, entitiesDB,
BuildGhostBlueprintFactory, false, bssesopt.Get().buildingDroneReference,
FullGameFields._managers.blockLabelResourceManager);
}
}
public Block[] PlaceBlueprintBlocks(uint blueprintID, uint playerID, float3 pos, float3 rot)
{ //RobocraftX.CR.MachineEditing.PlaceBlueprintUtility.PlaceBlocksFromSerialisedData
var serializationData = clipboardManager.GetSerializationData(blueprintID);
var blueprintData = serializationData.blueprintData;
blueprintData.dataPos = 0U;
uint selectionSize;
PositionEntityStruct selectionPosition;
RotationEntityStruct selectionRotation;
uint version;
BoxSelectSerializationUtilities.ReadClipboardHeader(blueprintData, out selectionSize, out selectionPosition, out selectionRotation, out version);
((FasterList<EGID>) LocalBlockMap.GetValue(null)).Clear();
if (version <= 1U)
{
uint groupsCount;
BoxSelectSerializationUtilities.ReadBlockGroupData(blueprintData, out groupsCount);
for (int index = 0; (long) index < (long) groupsCount; ++index)
{
int nextFilterId = BlockGroupUtility.NextFilterId;
entitySerialization.DeserializeNewEntity(new EGID((uint) nextFilterId, BlockGroupExclusiveGroups.BlockGroupEntityGroup), blueprintData, 1);
}
}
int nextFilterId1 = BlockGroupUtility.NextFilterId;
entityFactory.BuildEntity<BlockGroupEntityDescriptor>(new EGID((uint) nextFilterId1,
BlockGroupExclusiveGroups.BlockGroupEntityGroup)).Init(new BlockGroupTransformEntityComponent
{
blockGroupGridPosition = selectionPosition.position,
blockGroupGridRotation = selectionRotation.rotation
});
var frot = Quaternion.Euler(rot);
var grid = new GridRotationStruct {position = pos, rotation = frot};
var poss = new PositionEntityStruct {position = pos};
var rots = new RotationEntityStruct {rotation = frot};
for (int index = 0; (long) index < (long) selectionSize; ++index)
BuildBlock.Invoke(null,
new object[]
{
playerID, grid, poss, rots, selectionPosition, selectionRotation, blueprintData,
entitySerialization, nextFilterId1
});
/*
uint playerId, in GridRotationStruct ghostParentGrid,
in PositionEntityStruct ghostParentPosition, in RotationEntityStruct ghostParentRotation,
in PositionEntityStruct selectionPosition, in RotationEntityStruct selectionRotation,
ISerializationData serializationData, EntitiesDB entitiesDb,
IEntitySerialization entitySerialization, int blockGroupId
*/
if (globalBlockMap == null)
globalBlockMap = FullGameFields._deserialisedBlockMap;
var placedBlocks = (FasterList<EGID>) LocalBlockMap.GetValue(null);
globalBlockMap.Clear();
globalBlockMap.AddRange(placedBlocks);
BuildWires.Invoke(null,
new object[] {playerID, blueprintData, entitySerialization, entitiesDB, entityFactory});
var blocks = new Block[placedBlocks.count];
for (int i = 0; i < blocks.Length; i++)
blocks[i] = Block.New(placedBlocks[i]);
return blocks;
}
public void GetBlueprintInfo(uint blueprintID, out float3 pos, out quaternion rot, out uint selectionSize)
{
var serializationData = clipboardManager.GetSerializationData(blueprintID);
var blueprintData = serializationData.blueprintData;
blueprintData.dataPos = 0U;
BoxSelectSerializationUtilities.ReadClipboardHeader(blueprintData, out selectionSize, out var posst,
out var rotst, out _);
blueprintData.dataPos = 0U; //Just to be sure, it gets reset when it's read anyway
pos = posst.position;
rot = rotst.rotation;
}
public void InitBlueprint(uint blueprintID)
{
clipboardManager.IncrementRefCount(blueprintID);
}
public void DisposeBlueprint(uint blueprintID)
{
clipboardManager.DecrementRefCount(blueprintID);
}
//GhostChildUtility.BuildGhostChild
public Block BuildGhostChild()
{
var sourceId = new EGID(Player.LocalPlayer.Id, GHOST_BLOCKS_ENABLED.Group);
var positionEntityStruct = entitiesDB.QueryEntity<PositionEntityStruct>(sourceId);
var rotationEntityStruct = entitiesDB.QueryEntity<RotationEntityStruct>(sourceId);
var scalingEntityStruct = entitiesDB.QueryEntity<ScalingEntityStruct>(sourceId);
var dbStruct = entitiesDB.QueryEntity<DBEntityStruct>(sourceId);
var colliderStruct = entitiesDB.QueryEntity<ColliderAabb>(sourceId);
var colorStruct = entitiesDB.QueryEntity<ColourParameterEntityStruct>(sourceId);
uint ghostChildBlockId = CommonExclusiveGroups.GetNewGhostChildBlockID();
var ghostEntityReference = GhostBlockUtils.GetGhostEntityReference(sourceId.entityID, entitiesDB);
var entityInitializer = BuildGhostBlueprintFactory.Build(
new EGID(ghostChildBlockId, BoxSelectExclusiveGroups.GhostChildEntitiesExclusiveGroup), /*dbStruct.DBID*/ (uint)BlockIDs.Cube,
FullGameFields._managers.blockLabelResourceManager);
entityInitializer.Init(dbStruct);
entityInitializer.Init(new GFXPrefabEntityStructGPUI(
PrefabsID.GetOrCreatePrefabID((ushort)entityInitializer.Get<PrefabAssetIDComponent>().prefabAssetID,
entitiesDB.QueryEntity<CubeMaterialStruct>(sourceId).materialId, 7,
FlippedBlockUtils.IsFlipped(in scalingEntityStruct.scale)), true));
entityInitializer.Init(entitiesDB.QueryEntity<CubeMaterialStruct>(sourceId));
entityInitializer.Init(new GhostParentEntityStruct
{
ghostBlockParentEntityReference = ghostEntityReference,
ownerMustSerializeOnAdd = false
});
entityInitializer.Init(colorStruct);
entityInitializer.Init(colliderStruct);
entityInitializer.Init(new RigidBodyEntityStruct
{
position = positionEntityStruct.position,
rotation = rotationEntityStruct.rotation
});
entityInitializer.Init(new ScalingEntityStruct
{
scale = scalingEntityStruct.scale
});
entityInitializer.Init(new LocalTransformEntityStruct
{
position = positionEntityStruct.position,
rotation = rotationEntityStruct.rotation
});
entityInitializer.Init(new RotationEntityStruct
{
rotation = rotationEntityStruct.rotation
});
entityInitializer.Init(new PositionEntityStruct
{
position = positionEntityStruct.position
});
entityInitializer.Init(new SkewComponent
{
skewMatrix = entitiesDB.QueryEntity<SkewComponent>(sourceId).skewMatrix
});
entityInitializer.Init(new BlockPlacementInfoStruct
{
placedByBuildingDrone = entitiesDB
.QueryEntityOptional<BoxSelectStateEntityStruct>(new EGID(Player.LocalPlayer.Id,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup)).Get().buildingDroneReference
});
entityInitializer.Init(new GridRotationStruct
{
position = float3.zero,
rotation = quaternion.identity
});
var block = Block.New(entityInitializer.EGID);
block.InitData = entityInitializer;
return block;
}
public string Name { get; } = "TechbloxModdingAPIBlueprintGameEngine";
public bool isRemovable { get; } = false;
[HarmonyPatch]
private static class RemoveEnginePatch
{
public static void Prefix(IEntityFunctions entityFunctions,
MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory)
{
nativeRemove = entityFunctions.ToNativeRemove<BlockEntityDescriptor>("GCAPI" + nameof(BlueprintEngine));
connectionFactory = machineGraphConnectionEntityFactory;
BlueprintEngine.entityFunctions = entityFunctions;
}
public static MethodBase TargetMethod()
{
return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.RemoveBlockEngine"))[0];
}
}
[HarmonyPatch]
private static class SelectEnginePatch
{
public static void Prefix(ClipboardSerializationDataResourceManager clipboardSerializationDataResourceManager,
IEntitySerialization entitySerialization,
IEntityFactory entityFactory)
{
clipboardManager = clipboardSerializationDataResourceManager;
BlueprintEngine.entitySerialization = entitySerialization;
BlueprintEngine.entityFactory = entityFactory;
}
public static MethodBase TargetMethod()
{
return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.SelectBlockEngine"))[0];
}
}
[HarmonyPatch]
private static class SerializeGhostBlueprintPatch
{
public static void Postfix(object __instance)
{
SerializeGhostBlueprintInstance = __instance;
}
public static MethodBase TargetMethod()
{
return AccessTools.GetDeclaredConstructors(SerializeGhostBlueprintType)[0];
}
}
[HarmonyPatch]
private static class BuildGhostBlueprintPatch
{
public static void Postfix(GhostChildEntityFactory ghostChildEntityFactory)
{
BuildGhostBlueprintFactory = ghostChildEntityFactory;
}
public static MethodBase TargetMethod()
{
return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine"))[0];
}
}
public IEntityFactory Factory { get; set; }
}
}

View file

@ -1,21 +1,21 @@
using RobocraftX.Common;
using RobocraftX.UECS;
using RobocraftX.DOTS;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Transforms;
using Unity.Mathematics;
using Unity.Transforms;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
namespace TechbloxModdingAPI.Blocks.Engines
{
/// <summary>
/// Engine which executes block movement actions
/// </summary>
public class MovementEngine : IApiEngine
{
public string Name { get; } = "GamecraftModdingAPIMovementGameEngine";
public string Name { get; } = "TechbloxModdingAPIMovementGameEngine";
public EntitiesDB entitiesDB { set; private get; }
@ -35,12 +35,12 @@ namespace GamecraftModdingAPI.Blocks
// implementations for Movement static class
public float3 MoveBlock(EGID blockID, float3 vector)
internal float3 MoveBlock(Block block, float3 vector)
{
ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID);
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID);
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID);
ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID);
ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntityOrDefault<PositionEntityStruct>(block);
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntityOrDefault<GridRotationStruct>(block);
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntityOrDefault<LocalTransformEntityStruct>(block);
ref DOTSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntityOrDefault<DOTSPhysicsEntityStruct>(block);
// main (persistent) position
posStruct.position = vector;
// placement grid position
@ -48,18 +48,21 @@ namespace GamecraftModdingAPI.Blocks
// rendered position
transStruct.position = vector;
// collision position
FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Translation
{
Value = posStruct.position
});
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID).isProcessed = false;
if (phyStruct.ID != default)
{ //It exists
FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.dotsEntity, new Translation
{
Value = posStruct.position
});
}
entitiesDB.QueryEntityOrDefault<GridConnectionsEntityStruct>(block).isProcessed = false;
return posStruct.position;
}
public float3 GetPosition(EGID blockID)
internal float3 GetPosition(Block block)
{
ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID);
return posStruct.position;
return entitiesDB.QueryEntityOrDefault<PositionEntityStruct>(block).position;
}
}
}

View file

@ -0,0 +1,131 @@
using System.Reflection;
using DataLoader;
using Gamecraft.Blocks.BlockGroups;
using Gamecraft.Wires;
using HarmonyLib;
using RobocraftX.Blocks;
using RobocraftX.Character;
using RobocraftX.Common;
using RobocraftX.CR.MachineEditing.BoxSelect;
using RobocraftX.Rendering;
using RobocraftX.Rendering.GPUI;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Mathematics;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.Blocks.Engines
{
/// <summary>
/// Engine which executes block placement actions
/// </summary>
public class PlacementEngine : IApiEngine
{
public bool IsInGame;
public void Dispose()
{
IsInGame = false;
}
public void Ready()
{
IsInGame = true;
}
public EntitiesDB entitiesDB { get; set; }
private static BlockEntityFactory _blockEntityFactory; //Injected from PlaceSingleBlockEngine
private static IEntityFactory _entityFactory;
public EntityInitializer PlaceBlock(BlockIDs block, float3 position, Player player, bool autoWire)
{ //It appears that only the non-uniform scale has any visible effect, but if that's not given here it will be set to the uniform one
return BuildBlock((ushort) block, position, autoWire, (player ?? Player.LocalPlayer).Id);
}
private EntityInitializer BuildBlock(ushort block, float3 position, bool autoWire, uint playerId)
{
if (_blockEntityFactory == null)
throw new BlockException("The factory is null.");
if(!FullGameFields._dataDb.ContainsKey<CubeListData>(block))
throw new BlockException("Block with ID " + block + " not found!");
//RobocraftX.CR.MachineEditing.PlaceSingleBlockEngine
DBEntityStruct dbEntity = new DBEntityStruct {DBID = block};
//TODO: Test
EntityInitializer structInitializer = _blockEntityFactory.Build(CommonExclusiveGroups.blockIDGeneratorClient.Next(), block); //The ghost block index is only used for triggers
uint prefabAssetID = structInitializer.Has<PrefabAssetIDComponent>()
? structInitializer.Get<PrefabAssetIDComponent>().prefabAssetID
: throw new BlockException("Prefab asset ID not found!"); //Set by the game
uint prefabId = PrefabsID.GetOrCreatePrefabID((ushort) prefabAssetID, (byte) BlockMaterial.SteelBodywork, 1, false);
structInitializer.Init(new GFXPrefabEntityStructGPUI(prefabId));
structInitializer.Init(dbEntity);
structInitializer.Init(new PositionEntityStruct {position = position});
structInitializer.Init(new RotationEntityStruct {rotation = quaternion.identity});
structInitializer.Init(new ScalingEntityStruct {scale = new float3(1, 1, 1)});
structInitializer.Init(new GridRotationStruct
{
position = position,
rotation = quaternion.identity
});
structInitializer.Init(new UniformBlockScaleEntityStruct {scaleFactor = 1});
structInitializer.Get<CubeMaterialStruct>().materialId = (byte) BlockMaterial.SteelBodywork;
var bssesopt = entitiesDB.QueryEntityOptional<BoxSelectStateEntityStruct>(new EGID(playerId,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup));
if (!bssesopt)
throw new BlockException("Invalid player ID specified for block placement");
structInitializer.Init(new BlockPlacementInfoStruct
{
loadedFromDisk = false,
placedByBuildingDrone = bssesopt.Get().buildingDroneReference,
triggerAutoWiring = autoWire && structInitializer.Has<BlockPortsStruct>()
});
int nextFilterId = BlockGroupUtility.NextFilterId;
structInitializer.Init(new BlockGroupEntityComponent
{
currentBlockGroup = nextFilterId
});
_entityFactory.BuildEntity<BlockGroupEntityDescriptor>((uint) nextFilterId,
BlockGroupExclusiveGroups.BlockGroupEntityGroup)
.Init(new BlockGroupTransformEntityComponent
{
blockGroupGridRotation = quaternion.identity,
blockGroupGridPosition = position
});
foreach (var group in CharacterExclusiveGroups.AllCharacters)
{
EGID playerEGID = new EGID(playerId, group);
if (!entitiesDB.TryQueryEntitiesAndIndex<PickedBlockExtraDataStruct>(playerEGID, out uint index,
out var array)) continue;
ref PickedBlockExtraDataStruct pickedBlock = ref array[index];
pickedBlock.placedBlockEntityID = structInitializer.EGID;
pickedBlock.placedBlockWasAPickedBlock = false;
}
return structInitializer;
}
public string Name => "TechbloxModdingAPIPlacementGameEngine";
public bool isRemovable => false;
[HarmonyPatch]
class FactoryObtainerPatch
{
static void Postfix(BlockEntityFactory blockEntityFactory, IEntityFactory entityFactory)
{
_blockEntityFactory = blockEntityFactory;
_entityFactory = entityFactory;
Logging.MetaDebugLog("Block entity factory injected.");
}
static MethodBase TargetMethod(Harmony instance)
{
return AccessTools.TypeByName("RobocraftX.CR.MachineEditing.PlaceSingleBlockEngine").GetConstructors()[0];
}
}
}
}

View file

@ -3,12 +3,14 @@ using System.Reflection;
using HarmonyLib;
using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.Common;
using Svelto.ECS;
using Svelto.ECS.Native;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
namespace TechbloxModdingAPI.Blocks.Engines
{
public class RemovalEngine : IApiEngine
{
@ -20,8 +22,11 @@ namespace GamecraftModdingAPI.Blocks
if (!entitiesDB.Exists<MachineGraphConnectionsEntityStruct>(target))
return false;
var connections = entitiesDB.QueryEntity<MachineGraphConnectionsEntityStruct>(target);
var groups = entitiesDB.FindGroups<MachineGraphConnectionsEntityStruct>();
using var connStructMapper = //The allocator needs to be persistent because that's what is used in the Dispose() method
entitiesDB.QueryNativeMappedEntities<MachineGraphConnectionsEntityStruct>(groups, Allocator.Persistent);
for (int i = connections.connections.Count<MachineConnectionStruct>() - 1; i >= 0; i--)
_connectionFactory.RemoveConnection(connections, i, entitiesDB);
_connectionFactory.RemoveConnection(connections, i, connStructMapper);
_entityFunctions.RemoveEntity<BlockEntityDescriptor>(target);
return true;
}
@ -36,12 +41,12 @@ namespace GamecraftModdingAPI.Blocks
{
}
public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";
public string Name { get; } = "TechbloxModdingAPIRemovalGameEngine";
public bool isRemovable => false;
[HarmonyPatch]
public class FactoryObtainerPatch
class FactoryObtainerPatch
{
static void Postfix(IEntityFunctions entityFunctions,
MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory)

View file

@ -0,0 +1,73 @@
using RobocraftX.Common;
using RobocraftX.DOTS;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Mathematics;
using UnityEngine;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.Blocks.Engines
{
/// <summary>
/// Engine which executes block movement actions
/// </summary>
public class RotationEngine : IApiEngine
{
public string Name { get; } = "TechbloxModdingAPIRotationGameEngine";
public EntitiesDB entitiesDB { set; private get; }
public bool isRemovable => false;
public bool IsInGame = false;
public void Dispose()
{
IsInGame = false;
}
public void Ready()
{
IsInGame = true;
}
// implementations for Rotation static class
internal float3 RotateBlock(Block block, Vector3 vector)
{
ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntityOrDefault<RotationEntityStruct>(block);
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntityOrDefault<GridRotationStruct>(block);
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntityOrDefault<LocalTransformEntityStruct>(block);
ref DOTSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntityOrDefault<DOTSPhysicsEntityStruct>(block);
// main (persistent) rotation
Quaternion newRotation = rotStruct.rotation;
newRotation.eulerAngles = vector;
rotStruct.rotation = newRotation;
// placement grid rotation
gridStruct.rotation = newRotation;
// rendered rotation
transStruct.rotation = newRotation;
// collision rotation
if (phyStruct.ID != default)
{ //It exists
FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.dotsEntity,
new Unity.Transforms.Rotation
{
Value = rotStruct.rotation
});
}
entitiesDB.QueryEntityOrDefault<GridConnectionsEntityStruct>(block).isProcessed = false;
return ((Quaternion)rotStruct.rotation).eulerAngles;
}
internal float3 GetRotation(Block block)
{
ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntityOrDefault<RotationEntityStruct>(block);
return ((Quaternion) rotStruct.rotation).eulerAngles;
}
}
}

Some files were not shown because too many files have changed in this diff Show more