LUA Sockets / Multiplayer

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
yokmp
Posts: 4
Joined: Thu Jan 08, 2015 10:09 am

LUA Sockets / Multiplayer

Post by yokmp »

Hi dear readers!

First thing first, this is a pure 'Theory crafting Post'. So not a single Line of code is actually written.

A couple of Days ago i thought it would be cool to play some kind of Arena Match against Friends. So i searched the Forums and Steam communitys for some kind of Multiplayer Mod but with no Luck. I wondered because there is actually a LUA Socket Module out there. And with tools like Hamachi we could easily connect to each other.

Im not that confident in Grimrock modding to tell if this is an easy step, but it seems possible. As described in the scripting reference it can load external LUA modules with:

Code: Select all

ScriptComponent:loadFile(filename)
ScriptComponent:setSource(source)
The benefit of the LUA Socket thingy is, its OS independent so there is no need to fiddle around and besides that its easy to use. Or at least easier than writing own stuff and whatnot.

Lets say we've done all this, now we need some kind of handler/server. Some thing that sends gathered informations/actions we did to the other persons handler/server (NOTE:)
SpoilerShow
who ever hosts, this should be figured out at first to write code in that direction
ie. let the game sync player A and B and then send the diff between them
or let a server handle this stuff which means we either write an entire new server and also dissasemble the .dat file or use Player As game to host it.
And what exactly should be send to each others game? Ie. do we want 1v1 or Party vs Party? We should also use custom Models to display Player Bs Char/Party in Player As game and vice versa. But as long as we play A vs B its ok to go with some ingame Model ...

So its not only the technical Part but also the Artistical (ie Models etc) one which must be done at some point. I have no idea when it comes to Modeling but im ok with logical stuff and Programming. Lua isn't my best Lang to go but its well documented.

At least i think its not that big kind of deal to port it to Grimrock 2 since its technicaly the same Game as far as i could see in the manuals. (ps i don't own Grimrock 2 ... shame on me.)

Now my questions are, is there even a need for this and who wants to help?
Do you guys 'n girls have any suggestions etc?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: LUA Sockets / Multiplayer

Post by minmay »

The scripting interface will only execute Lua code. Allowing you to put arbitrary instructions in your mods is literally the most unsafe thing possible; no sane developer would allow it, and no sane modding site would host said mods. Barring a massive security hole in Lua and/or Grimrock, all you can execute is Lua in the script interface environment.
You would have to either:
1. modify grimrock.dat or the executable, which I believe is against the EULA, and distributing them would definitely be.
2. modify the process at runtime (such as injecting a DLL), probably also against the EULA to distribute.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: LUA Sockets / Multiplayer

Post by JohnWordsworth »

Unfortunately, I believe there is a C component to LuaSockets which needs to be compiled into the application, as well as the Lua component. Unless Almost Human decides to add it for the fun of seeing what we do with it, I think it would take a fair bit of injection and code hacking to get it to work. I could be wrong though!

it would be pretty fun to toy around with an MP mode, but there are no player character models - what would you show when you see another player? Cool idea though. Could picture it running with a dungeon master player controller the world a little too (advanced mode).

If it does turn out to be doable, I'd love to see it come along!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
yokmp
Posts: 4
Joined: Thu Jan 08, 2015 10:09 am

Re: LUA Sockets / Multiplayer

Post by yokmp »

It doesn't seem to be forbidden to inject a dll file. As I interpret the licence.txt, it is allowed as long as im the owner of the code and i also provide the source and add the license.txt file.
Copy&Paste magic:
SpoilerShow
3. Distribution Obligations.

3.1. Application of License.
The Modifications which You create or to which You contribute are governed by the terms of this License, including without limitation Section 2.2. The Source Code version of Covered Code may be distributed only under the terms of this License or a future version of this License released under Section 6.1, and You must include a copy of this License with every copy of the Source Code You distribute. You may not offer or impose any terms on any Source Code version that alters or
restricts the applicable version of this License or the recipients' rights hereunder. However, You may include an additional document offering the additional rights described in Section 3.5.

3.2. Availability of Source Code.
Any Modification which You create or to which You contribute must be made available in Source Code form under the terms of this License either on the same media as an Executable version or via an accepted Electronic Distribution Mechanism to anyone to whom you made an Executable version available; and if made available via Electronic Distribution Mechanism, must remain available for at least twelve (12) months after the date it initially became available, or at least six (6) months after a subsequent version of that particular Modification has been made available to such recipients. You are responsible for ensuring that the Source Code version remains available even if the Electronic Distribution Mechanism is maintained by a third party.

3.3. Description of Modifications.
You must cause all Covered Code to which you contribute to contain a file documenting the changes You made to create that Covered Code and the date of any change. You must include a prominent statement that the Modification is derived, directly or indirectly, from Original Code provided by the Initial Developer and including the name of the Initial Developer in (a) the Source Code, and (b) in any notice in an Executable version or related documentation in which You describe the origin or ownership of the Covered Code.

3.4. Intellectual Property Matters

(a) Third Party Claims.
If You have knowledge that a party claims an intellectual property right in particular functionality or code (or its utilization under this License), you must include a text file with the source code distribution titled "LEGAL" which describes the claim and the party making the claim in sufficient detail that a recipient will know whom to contact. If you obtain such knowledge after You make Your Modification available as described in Section 3.2, You shall promptly modify the LEGAL file in all copies You make
available thereafter and shall take other steps (such as notifying appropriate mailing lists or newsgroups) reasonably calculated to inform those who received the Covered Code that new knowledge has been obtained.

(b) Contributor APIs.
If Your Modification is an application programming interface and You own or control patents which are reasonably necessary to implement that API, you must also include this information in the LEGAL file.

3.5. Required Notices.
You must duplicate the notice in Exhibit A in each file of the Source Code, and this License in any documentation for the Source Code, where You describe recipients' rights relating to Covered Code. If You created one or more Modification(s), You may add your name as a Contributor to the notice described in Exhibit A. If it is not possible to put such notice in a particular Source Code file due to its
structure, then you must include such notice in a location (such as a relevant directory file) where a user would be likely to look for such a notice. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Code. However, You may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear than any such warranty, support, indemnity or
liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of
warranty, support, indemnity or liability terms You offer.

3.6. Distribution of Executable Versions.
You may distribute Covered Code in Executable form only if the requirements of Section 3.1-3.5 have been met for that Covered Code, and if You include a notice stating that the Source Code version of the Covered Code is available under the terms of this License, including a description of how and where You have fulfilled the obligations of Section 3.2. The notice must be conspicuously included in any notice in an Executable version, related documentation or collateral in which You
describe recipients' rights relating to the Covered Code. You may distribute the Executable version of Covered Code under a license of Your choice, which may contain terms different from this License,
provided that You are in compliance with the terms of this License and that the license for the Executable version does not attempt to limit or alter the recipient's rights in the Source Code version from the rights set forth in this License. If You distribute the Executable version under a different license You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or any Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer.

3.7. Larger Works.
You may create a Larger Work by combining Covered Code with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Code.
Basically, as far as I understand, it's even possible to use a 3rd party injector for this task. Then we could load a not so 'cut-to-death' LuaJiT version which allows us to use os functions. Im pretty shure we dont need IO stuff because this art should be handeld by the Lua Socket Module.
So we just need to edit the paths in the variables CC, CINC, LUAINC and LUADLL, compile it under (let's say) mingw, put in LuaSocket and thats it. Basically.

But this also means, that the user who wants to use the MP mod must have this version of LuaJiT installed. Am i right? Im not shure if we can pack it all together as a sort of a stand alone package.
We can now use Hamachi to send our stuff i think. Or press a button to ping google LOL
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: LUA Sockets / Multiplayer

Post by minmay »

That's the FreeImage Public License you just pasted, not the Grimrock license...this is the Grimrock license:
SpoilerShow
LEGEND OF GRIMROCK 2
END USER LICENSE AGREEMENT

THIS END USER LICENSE AGREEMENT IS A LEGAL AGREEMENT BETWEEN ALMOST HUMAN LTD AND YOU (EITHER AN INDIVIDUAL OR, IF ACQUIRED BY OR FOR AN ENTITY, AN ENTITY).

THE SOFTWARE IS LICENSED, NOT SOLD. ALMOST HUMAN LTD OWNS ALL INTELLECTUAL PROPERTY RIGHTS IN THE LEGEND OF GRIMROCK 2 COMPUTER GAME SOFTWARE AND PERMITS YOU TO USE THE LEGEND OF GRIMROCK 2 COMPUTER GAME SOFTWARE ONLY IN ACCORDANCE WITH THE TERMS OF THIS AGREEMENT.

THE USE OF THE LEGEND OF GRIMROCK 2 COMPUTER GAME SOFTWARE MAY REQUIRE AN ACTIVE STEAM ACCOUNT AND INSTALLATION OF STEAM CLIENT TO THE COMPUTER YOU WISH TO USE THE GAME FROM. IN SUCH A CASE THE STEAM CLIENT SHALL BE PROVIDED TOGETHER WITH THE GAME OR IT CAN BE OBTAINED FREE OF CHARGE FROM THE STEAM STORE LOCATED AT HTTP://STORE.STEAMPOWERED.COM. BEFORE INSTALLING THE STEAM CLIENT AND/OR CREATING A STEAM ACCOUNT YOU MIGHT BE REQUIRED TO ACCEPT CERTAIN TERMS AND CONDITIONS OF VALVE CORPORATION THE OWNER OF STEAM.

PLEASE READ THIS AGREEMENT CAREFULLY BEFORE ACCESSING THE SOFTWARE MEDIA, INSTALLING, STARTING OR OTHERWISE USING THE LEGEND OF GRIMROCK 2 COMPUTER GAME SOFTWARE. ANY OF THE ABOVE ACTIONS INDICATE THAT YOU HAVE READ ALL OF THE TERMS AND CONDITIONS OF THIS AGREEMENT, UNDERSTAND THEM, AND AGREE TO BE LEGALLY BOUND BY THOSE TERMS AND CONDITIONS. IF YOU DO NOT AGREE TO THE TERMS OF THIS AGREEMENT, DO NOT INSTALL, USE OR ACCESS THE SOFTWARE.

1 DEFINITIONS
1.1 "Agreement" shall mean this License Agreement.
1.2 “Documentation” shall mean any online and/or electronic documentation, specifications, instructions, associated media and any other materials related to the Game as provided by Almost Human.
1.3 "Almost Human" shall mean Almost Human Ltd, Kalastajankuja Keilaranta 14 A, 0223150 Espoo, Finland, and its licensors, if any.
1.4 "Intellectual Property Rights" shall mean any and all intellectual property rights including but not limited to patents, copyrights, trademarks, trade secrets, trade names, titles, computer codes, characters, character names, stories, dialog, settings, artwork, theme, sounds effects, know-how, moral rights, registrations, applications, and rights to apply therefore, whether issued or pending and whether registerable or not.
1.5 "License" shall mean the right to use the Game under this Agreement.
1.6 "Licensee" shall mean You.
1.7 "Party" or "Parties" shall refer to the parties of this Agreement.
1.8 "Game" shall mean the computer game software titled “Legend of GrimrockLEGEND OF GRIMROCK 2”, licensed under this Agreement.
1.9 "Use" or "Using" means to access, download, install, copy, load, run and operate or otherwise benefit from using the functionality of the Game solely in accordance with the Documentation.

2 GRANT OF LICENSE
2.1 Subject to the terms and conditions of this Agreement and the Documentation Almost Human hereby grants You during the validity of this Agreement a world-wide, non-transferable, non-exclusive, non-sublicensable, revocable right and license to use the Game for Your personal purposes and download one back-up copy of the Game and operate the Game for that purpose.
2.2 You hereby acknowledge and agree that the License gives You only limited License and all rights, title and interest, including but not limited to all intellectual property rights in and to the Game, new versions, upgrades, updates, modifications, enhancements or copies thereof, and the ownership rights to the Game shall solely remain with Almost Human and/or its licensors.
2.3 You may use the Game for Your personal purposes and You may install the Game for this purpose in multiple computers to be used one at a time. You may make one back-up copy of the Game, only to be used in the event that the original copy of the Game fails to function, is lost, damaged or destroyed. You warrant that You will make no other copies of the Game and will not allow, authorize or assist others to copy any part or all of the Game in any form without the prior written approval of Almost Human.
2.4 The Software may allow you to create content, including but not limited to gameplay maps, screenshots or a video of your game play. In exchange for use of the Game, and to the extent that your contributions through use of the Game give rise to any copyright, design right or any other intellectual or industrial property right you hereby grant Almost Human an exclusive, royalty-free, perpetual, irrevocable, fully transferable and sub-licensable worldwide right and license to use your contributions in any way and for any purpose including, but not limited to the rights to reproduce, copy, adapt, modify, perform, display, publish, broadcast, transmit, or otherwise communicate to the public by any means whether now known or unknown and distribute your contributions without any further notice or compensation to you of any kind for the whole duration of protection granted to intellectual and industrial property rights by applicable laws and international conventions. If not expressly prohibited by mandatory legislation, you hereby waive any moral rights of paternity, publication, reputation, or attribution with respect to Almost Human's and other players' use and enjoyment of such assets in connection with the Software and related goods and services under applicable law. This license grant to Almost Human, and the above waiver of any applicable moral rights, survives any termination of this License.
2.5 The License is valid only for as long as this Agreement is in force and the Licensee operates under the terms and conditions of this Agreement.
2.6 For avoidance of doubt, notwithstanding anything to the contrary, the Parties expressly agree that the license terms or any other terms of this Agreement may be altered by written agreement of the Parties.

3 LICENSE RESTRICTIONS
3.1 The Licensee shall neither cause nor permit any reverse engineering, disassembling, decompilation, translation, modification, adaptation of the Game or extraction of any part of the Game or otherwise attempt to learn the inner workings, source code, structure, algorithms, artwork or ideas underlying in the Game. Licensee is expressly prohibited from adapting, modifying, revising, improving, upgrading, enhancing and creating derivative works of the Game for any purpose including error correction or any other type of maintenance, except as expressly allowed in the Documentation.
3.2 Licensee warrants that it will not commercially exploit, sell, license, lease, rent, loan, lend, transmit, network, or otherwise distribute or transfer the Game, or any copies of the Game, in any manner to any third party.

4 RIGHTS TO THE GAME
4.1 Any and all proprietary and Intellectual Property Rights associated with or arising from the Game and related materials and Documentation belong and remain solely with Almost Human and/or its licensors. All rights not expressly granted to you herein are reserved by Almost Human.
4.2 The License shall not give the Licensee any ownership or title to the Game or any related Documentation.

5 DISCLAIMER OF WARRANTY AND LIMITATIONS OF LIABILITY
5.1 THE GAME IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
5.2 ALMOST HUMAN HAS TESTED THE GAME EXTENSIVELY IN A NUMBER OF DIFFERENT SETUPS, PCS AND PERSONAL COMPUTERS AND ALSO TESTED IT AGAINST ANY KNOWN VIRUSES, BUT YOU ASSUME THE ENTIRE RISK AS TO THE USAGE, RESULTS AND PERFORMANCE OF THE GAME. ALMOST HUMAN AND ITS AUTHORIZED DISTRIBUTORS ASSUME NO RESPONSIBILITY FOR THE ACCURACY OR APPLICATION OF OR ERRORS OR OMISSIONS IN THE GAME.
5.3 LICENSEE ACKNOWLEDGES THAT ALMOST HUMAN HAS NO CONTROL OVER LICENSEE'S USE OR EXPLOITATION OF THE GAME. LICENSEE THEREFORE AGREES TO INDEMNIFY AND HOLD ALMOST HUMAN HARMLESS AGAINST ANY COSTS, CLAIMS, DEMANDS, EXPENSES AND LIABILITIES OF WHATSOEVER NATURE BY ANY THIRD PARTY ARISING FROM SUCH USE OR EXPLOITATION.
5.4 IN NO EVENT SHALL ALMOST HUMAN OR ITS AUTHORIZED DISTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE GAME, EVEN IF ALMOST HUMAN OR ITS AUTHORIZED DISTRIBUTORS HAVE BEEN ADVISED OF THE LIKELIHOOD OF SUCH DAMAGES OCCURRING. ALMOST HUMAN AND ITS AUTHORIZED DISTRIBUTORS SHALL NOT BE LIABLE FOR ANY LOSS, DAMAGES OR COSTS, ARISING OUT OF, BUT NOT LIMITED TO, LOST PROFITS OR REVENUE, LOSS OF USE OF THE GAME OR THE MEDIA, LOSS OF DATA OR EQUIPMENT, THE COSTS OF RECOVERING THE GAME, THE MEDIA, DATA OR EQUIPMENT, THE COST OF SUBSTITUTE GAME, MEDIA, DATA OR EQUIPMENT OR CLAIMS BY THIRD PARTIES, OR OTHER SIMILAR COSTS.
5.5 SINCE LOCAL LEGISLATION IN SOME COUNTRIES DOES NOT ALLOW ANY EXCLUSION OR LIMITATION OF IMPLIED WARRANTIES OR LIMITATION OF LIABILITY FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES; THE ABOVE LIMITATIONS OR EXCLUSIONS MAY APPLY TO YOU ONLY PARTLY OR NOT AT ALL.
5.6 IN ANY EVENT, IF ANY STATUTE IMPLIES WARRANTIES OR CONDITIONS NOT STATED IN THIS LICENSE AGREEMENT, ALMOST HUMAN'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS LICENSE AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY LICENSEE TO LICENSE THE GAME.

6 TERMINATION OF THE LICENSE
6.1 This Agreement will terminate automatically if you fail to comply with its terms and conditions. In such event, you must destroy all copies of the Software and all of its component parts and cease and desist from accessing any service components of the Software. With regards to Software delivered on a physical storage medium you can end this Agreement by destroying the Software and all copies and reproductions of the Software and deleting and permanently purging the Software from any client server or computer on which it has been installed.

7 INDEMNITY
7.1 You agree to indemnify, defend and hold Almost Human, its partners, licensors, affiliates, contractors, officers, directors, shareholders, employees and agents harmless from all damages, losses and expenses arising directly or indirectly from your acts and omissions to act in using the Game pursuant to the terms of the Agreement.

8 MISCELLANEOUS
8.1 No delay by either Party in enforcing the provisions of this Agreement shall prejudice or restrict its rights nor shall any waiver of rights operate as a waiver of any subsequent breach.
8.2 If any provision of this Agreement or the application of any such provision would be invalid, void or unenforceable and/or should be held by a Court of competent jurisdiction to be contrary to law, the remaining provisions of this Agreement shall remain in full force and effect to the maximum extent permissible by the applicable law.
8.3 This Agreement is made, executed and delivered in Espoo, Finland and any controversy arising hereunder or relation to this Agreement shall be governed by and construed in accordance with the laws of Finland, excluding its choice of law provisions. The parties hereto hereby agree that the United Nations Convention on Contracts for the International Sale of Goods does not apply to this Agreement and is strictly excluded in all proceedings.
8.4 In the event of any dispute between Licensee and Almost Human under this Agreement, the Parties agree that they shall negotiate with each other in good faith in an attempt to resolve the dispute prior to any commencement of proceedings.
8.5 All disputes arising in connection with this Agreement, its negotiations, performance, breach, existence or validity shall be determined by final arbitration in Helsinki, Finland, in accordance with the Arbitration Rules of the International Chamber of Commerce, in the English language. The Parties agree to be bound by the arbitrator's decision. However, if the Licensee is considered to have a status of a consumer, Almost Human might and is fully capable of choosing another jurisdiction and forum such as forum of domicile of the Licensee. In such a case the applicable law of the proceedings will be the national trade law or, when obligatory, the consumer legislation of the said forum. This might be especially applicable to those consumers residing in the European Union.
8.6 I acknowledge that I have the authority to execute this Agreement on behalf of the Licensee and I further acknowledge and agree that this Agreement constitutes a valid and legally binding obligation on the part of the Licensee.
8.7 BY ENTERING INTO THIS AGREEMENT, YOU EXPRESSLY WAIVE THE RIGHT TO PARTICIPATE IN A CLASS ACTION AGAINST ALMOST HUMAN.

IF YOU HAVE ANY QUESTIONS CONCERNING THIS LICENSE, YOU MAY CONTACT contact@almosthumangames.com.
The relevant clause here (also found in pretty much every other commercial software product these days) is:
3.1 The Licensee shall neither cause nor permit any reverse engineering, disassembling, decompilation, translation, modification, adaptation of the Game or extraction of any part of the Game or otherwise attempt to learn the inner workings, source code, structure, algorithms, artwork or ideas underlying in the Game. Licensee is expressly prohibited from adapting, modifying, revising, improving, upgrading, enhancing and creating derivative works of the Game for any purpose including error correction or any other type of maintenance, except as expressly allowed in the Documentation.
Not all parts of the EULA are necessarily enforceable in all relevant countries (for example, class action waivers are often challenged, with mixed success), and I'm not a lawyer, but it looks to me that modification of the game very much is against the EULA. I don't know if DLL injection specifically counts.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
yokmp
Posts: 4
Joined: Thu Jan 08, 2015 10:09 am

Re: LUA Sockets / Multiplayer

Post by yokmp »

The injection itself maybe not. I mean Steam ond Overwolf also use this to display an overlay GUI. The Problem maybe is, that the dll will communicate with the internal Lua thingy to get and set informations (ie Player pos, used items, Char attributes etc). On the other hand, they allowed people to extract files from their .dat file. So this is basically against the license point in 3.1 but its still available to get via forum link (ie python extractor). Plus the ModTool which already provides the functionalities to get the informations we need.

We only use the dll to pass this stuff to an external program which sends it over the net to another program which sends them via the dll back to the game/lua. I didnt work with the exe to crack it or something nor do i manipulate its code or read out the memory.
We don't modify the Game but use the already provided modding capabilities (LuaJiT).
I just want to talk :3

It would be helpful if anyone of the Moderators could answer the question if its allowed or not.

(quick edit: maybe there is a diff between the methods used to inject like ASM/EIP/ESP or QueueUserAPC or SetWindowsHookEx ..?)
Post Reply