Leaderboard
Popular Content
Showing content with the highest reputation on 24/10/24 in all areas
-
The SCM Interpreter (New Discord server: https://discord.gg/GBPZ9GvVdw) Filled with excitement I am here to announce a project that I have been working on together with @GTX named Sphene. In this post I will be talking about SCM, what Sphene has to do with it, our current development and what we plan for the future. Before I tell you what Sphene is I first need to give you some background on what SCM is as this plays an important factor in this project. I will not keep you waiting so let's get starting! What is SCM? Many of you may have heard, seen or even tampered with a well known file "main.scm" in your GTA: San Andreas installation. This file (notice the '.scm' extension) contains all the mission scripts that are available in singleplayer. Essentially the whole story-line and its side-missions are stored in here. The reality for side-missions is a bit more complicated but for the sake of this explanation we'll keep that aside as to keep it simple. SCM is the name of the language this file has been written in by Rockstar Games. Since it was made by them and the file is compiled (converted into a format that can be easily read by the game but not easily by a human) we unfortunately do not know what the original code looked like. Modders all across the world use a tool named SannyBuilder to write SCM themselves but this is very unlikely to look anywhere near the original format created by Rockstar Games. But, this does not matter much to us as it still compiles into the same format readable by the game. Essentially a compiled SCM file contains a big variety of "instructions" which tell the game what to do. For example there is an instruction that makes the game spawn a car on specific coordinates, tell a ped to drive or that tells the game to jump to a different location in the script and execute the instructions on this new position. For those wanting more in-depth information I highly recommend to read the SCM section in the "GTA SA modding book" by fastman92 which can be found here. So, what does Sphene have to do with this? Sphene is a SCM Interpreter, as in, it can run files created in the SCM language and which are compiled, including the "main.scm" file from the singleplayer game. This means that we can recreate all of singleplayer within Multi Theft Auto and further extend it with a big variety of features and improvements. Sounds great, doesn't it? It sounds easier than it is in reality however. The reality is that, as explained in the SCM section, these scripts tell the game what steps to perform, but the game still has to perform them. What does this mean? Well, it means we have to implement each instruction ourselves and make sure we stick as close to the actual game while doing so. Some instructions are fairly easy and quick to implement while others are a lot more complicated. Why? Because on many instructions the game doesn't perform just a single action. Let us take the instruction (or as we commonly refer to an instruction: opcode) to make a car drive as an example: 0704: car $car_pointer drive_to 1250 -75.5 13.25 Taken from 'SASCM.ini' included in SannyBuilder 3. The identifier for this instruction is '0704', through this Sphene knows this is the car_drive_to instruction and how many parameters (information given together with this instruction, in this case what car we want to get driving and to which location) to expect. Seems easy enough, except that there is no simple MTA function to get a car driving to a specific location. No, instead we have to write our own logic to make this possible. This can become very complex very quickly, especially as the exact functionality of many instructions isn't even known. Reverse engineering Because of this complexity and the need to make Sphene work as close to the actual game as possible we have started to reverse engineer GTA SA. Reverse engineering means that we try to make sense of the compiled code of the actual game and try to turn it into human readable code. This is easier said than done though, it's a lot more complex than reverse engineering a SCM file is. Luckily the big modding community (including MTA devs/contributors) have managed to reverse engineer big chunks of the game already, we just have to fill in the gaps that hasn't been reverse engineered yet but that contains chunks of code we require to make Sphene as accurate as possible. Contributing to Multi Theft Auto Using this knowledge and to make development easier for us (and simultaneously contributing to the MTA community as a whole) we have started contributing to the Multi Theft Auto codebase. There already is a work in progress pull request (a request for code to be added to MTA) to make it possible for players to drive client-side vehicles, damage them and other improvements. This is not only useful for us but many other servers as well. Okay, what is the purpose then? Why don't we just play singleplayer? Good question. Sphene will introduce many new options to make the game behave differently. This can be a setting to have much smarter ped AI's (making the game more difficult) to other settings to enhance the gameplay or raise its difficulty. We're not just interpreting the SCM but can actively improve it. There surely must be more to it? Oh, you bet. Did you ever want to play the storyline together with a friend (or multiple friends)? We are introducing Co-Op which allows exactly this. Naturally this version of the game will contain small changes to accommodate for the existence of multiple players and will be a lot harder. Although extra settings can raise that difficulty even more (1 HP limit anyone?). (Click to enlarge) This is a concept design of the Co-Op lobby designed by AnarchY. Anything else? Did I forget to mention that we are also planning support for GTA III and GTA Vice City (data files will have to be provided by yourself in order to load these in, to make sure you do own these games legitimately) into Sphene? I did? Well, I am happy to announce that we have already start adding basic support for these games and are hoping to make them available not long after we complete the support for GTA: San Andreas. The difficulty of implementing support for these games is of course greater as we have to import their full maps, recreate their controls, etc... That's nice, but how is the current development going? I am glad that you are asking. Sphene started out as a personal experiment but has quickly grown into a big and stable project. We started with implementing support for basic instructions and basic game logic that allowed us to fully get a tiny, custom, SCM file with a small mission working. This mission consisted of the following steps: Step in the nearly exploding car marked by the arrow. Drive the car to a checkpoint without further damaging it. Get out of the car and kill the NPC with the arrow above its head. Mission passed Very simple, but great for initially testing the interpreter. Screenshots were taken from an internal video at the time of said development. A small debug panel (improved in later stages) is seen on the right showing the instructions being executed by the interpreter. (Click to enlarge) This worked great, so now it was time to start implementing the instructions for the actual game. This proved to be challenging very quickly due to the high amount of instructions the game calls before even visually showing anything to you. But, eventually we did implement the instructions and proper text drawing support for the well known start of the game. That was a great start. Although it didn't go as well as planned as this text kept disappearing and re-appearing in a loop. Great. Now I had to figure out why this was the case. In order words, I had to start reverse engineering all the instructions Sphene was going through and manually going through the compiled SCM file instruction by instruction to make sure Sphene was interpreting everything correctly. Eventually I managed to find the issue and resolved it. A larger version of the debug panel was then being developed (for more in-depth information) and later on improved multiple times. It didn't take too long before everything was implemented to allow us to get to the famous "Grove Street -Home." sequence. Complete with audio! (Click to enlarge) We then proceeded to improve performance further and mostly do bug fixing. Currently the interpreter can handle instructions up to the sequence in the first mission where you need to get on a bike after a Ballas drive-by occurs. Although due to the amount and type of instructions implemented we did already make it possible for Sphene to run the Kickstart and Bloodring (partially) minigames as well. This truly shows that when we implement more and more instructions a lot more of the game will automatically start becoming available. (Click to enlarge) Future development We are of course still implementing a lot of instructions, improving our overall code (fixing bugs and improving performance), adding more game logic, etc. Not only that, we actually have attempted (and will continue working on it in the future) to implement cutscenes. This did not go well at first as it caused a lot of crashes, misaligned objects, etc. But we got it reasonably working, aside from the NPC's that are not animated whatsoever and float weirdly in the air. We hope to get cutscenes up and running soon. The lobby (for Co-Op) will also be implemented soon and similarly we will start develop on the Co-Op portion of Sphene. After we launch a first version (with GTA: San Andreas support) we will continue development on the GTA: Vice City and GTA III portions. We also plan (and slowly started) to develop a decompiler and compiler for SCM straight into Sphene and build our own language around it that compiles to SCM. This will allow for user created storyline's, missions, etc that also work in singleplayer if you so desire. The reason we'll be building our own language rather than using the SannyBuilder syntax is simply the fact that there is no standard SCM coding syntax out there and the SannyBuilder one is often too complex and not intuitive for most people. We want our implementation of it to be closer to what people expect from modern programming languages. (Click to enlarge) That's it for this post. Please leave any questions and/or remarks in the comments! Sincerely, Megadreams1 point
-
Dear Multi Theft Auto players and supporters! Today is the 20 Year Anniversary of Multi Theft Auto! On the February 9th 2003, a rudimentary GTA3 multiplayer prototype was released by our founder, IJsVogel. It did not take long for contributors to join the effort and turn it into a real multiplayer mod. The mod IJsVogel created was originally named “GTA3: Alternative Multiplayer”, but soon after it became “GTA3: Multi Theft Auto”. The Multi Theft Auto (MTA) name became the identity of all following projects. As new GTA games were released, new projects were created for GTA3, GTAVC, GTASA and GTAIV. Respectively, the main project names are: GTA3:MTA, MTA:VC, MTA:SA, MTA:IV. The development during GTA3 showed what the team was capable of with enough learning and reverse engineering. At this time, game modes were made for deathmatch and vehicle stunts. These game modes were hard-coded into the mod and could not be altered. It was not perfect, but it was an amazing accomplish for the time. Not only was it the first multiplayer for GTA, but it was an unprecedented undertaking. An early version of GTA3:MTA 0.2 (client and server). Some time in the first half of 2003. The working experience on GTA3 laid the framework for the second project, MTA:VC. It did not take long after GTA: Vice City for the 1st version of MTA:VC to release. The MTA Team succeeded in creating the basic multiplayer functionality much quicker through past-experience. At this point, MTA was well-known and there were mentions on gaming websites, magazines and even a TV interview on the gaming channel G4TV. Even Rockstar Games developers, the creators of GTA, contacted the MTA Team from time to time. The MTA:VC mod still offered a hard-coded deathmatch and vehicle stunting game mode that could not be altered. However, it had better synchronization and supported many new features. When GTA:SA came out, the contributors to the project were much more seasoned and mature. The 3rd project, MTA:SA, was much more ambitious. Although the first release was restricted to racing in vehicles, it was a proof of concept for a vastly superior framework that empowered users to make their own content. An editor was produced to allow in-game editing for the first time. When the full-featured product began development, a constantly evolving Lua-based scripting system accompanied it. This allowed the user to manipulate game code and modify various settings, elements and added features to create unique servers and game modes. Some added features include: voice chat, custom GUIs, web browser components. The MTA Team had the foresight to release this modification to the public as Open-Source code to attract future developers and embraced many new tools of game development that have become commonplace today such as installers, bug reporting, nightly builds, wiki documentation, anti-cheat, and Steam version support to name a few. MTA:SA 1.1 public tests. August, 2011. The release of GTA:IV did result in the beginning stages of MTA:IV, but once Rockstar released their official multiplayer, many of MTA’s most seasoned developers and contributors were ready to move on with their professional lives. Providing the same level of quality to GTA:IV would have been an extreme undertaking. It was decided that the best course of action would be to discontinue further projects and continue making MTA:SA better. The MTA:SA project still receives Open-Source contributions and still retains a consistent player base that is large enough to make developers of new games jealous! Thank You We would like to thank everyone who helped and participated over the years: developers, community/clan leaders, moderators, patch contributors, helpers, donators, testers, translators, scripters, mappers, server hosts/owners, streamers, players and fans. There were hundreds of thousands of such people over the years and they all had their place here. Many people have come and gone. Some are still very young and some are quite old now! Some of us have even developed life careers from our experiences working on this modification. We had the honor of befriending a lot of wonderful people in various stages of the project and many were just as enthusiastic about MTA as we were. Multi Theft Auto would not be here right now, had it not been for their hard work, interest and dedication. No seats? No problem. Screenshot from MTA:SA 1.0.5, taken by Zango. August, 2011. The social aspect has always been strong in MTA. No one knows what the future will bring, but there are things that will remain regardless of anything - and that is the time you all have spent here and your memories. Feel free to share your MTA stories in the comments! Feel free to say hi to us in Discord as well! Thank you all past and present MTA staff members, players and fans for sticking with us! Happy Birthday, Multi Theft Auto! Onwards to the next 20 years or more! -MTA Team1 point
-
Lua Metatables Guide Introduction Hello, I’m Shady, and I’m here with a new tutorial. At the bottom of this section, in the credits, you will find all the links to my other tutorials. Those should be your first priorities. I have prepared a tutorial that will help you explore metatables at an advanced level and set you on your way,The Lua programming language has gained popularity for its simple yet powerful syntax, making it a common choice for both game development and general-purpose programming. This guide will enable you to delve deep into the metatable feature of Lua and demonstrate how to apply object-oriented programming (OOP) concepts using metatables. Metatables are used to customize the behavior of tables in Lua and manage complex data structures. In this guide, we will focus on the following topics: What is a Metatable?: We will understand the concept of metatables and why they are used. Creating Classes with Metatables: We will create a simple Vector class and explore operator overloading methods. Inheritance: We will learn how to implement inheritance and override functions using metatables. Complex Scenarios: We will create more complex structures, such as a character class, using metatables in real-world applications. By the end of this guide, you will learn how to effectively utilize metatables in Lua, enhancing the functionality of your games or applications. So, let's step into the world of Lua metatables! What is Metatable? A metatable is a special table used to change the behavior of tables in Lua. With a metatable, you can inherit between tables and perform special operations. Creating Metatable... First, we need to create a metatable. We can define it as a simple table. myMetatable = {} Using Metatable in a Table To assign a metatable to a table, we use the setmetatable function myTable = {} setmetatable(myTable, myMetatable) Operator Overloading with Metatable Metatables can also be used for operator overloading. For example, let's define the __add function for addition. myMetatable.__add = function(t1, t2) return t1.value + t2.value end Adjusting the Values of Tables We can use the __index and __newindex methods in the metatable to set the values of tables. myMetatable.__index = function(table, key) return "Key not found: " .. key end myMetatable.__newindex = function(table, key, value) rawset(table, key, value) end Example of Use myTable.value = 5 local anotherTable = { value = 10 } setmetatable(anotherTable, myMetatable) local result = myTable + anotherTable print(result) -- 15 Metatable and Mapping Functions Metatables are used to provide functionality and inheritance relationships between tables in Lua. With special keys provided by the metatable, we can map between tables. Operator overloading functions like __index, __newindex, __add, and __sub allow us to change the behavior of tables. An Example in Depth: Vector Class Below, we will create a Vector class. This class will support addition, subtraction, and other vector operations. -- Creating the vector metatable Vector = {} Vector.__index = Vector -- Create a new vector function Vector:new(x, y) local vec = setmetatable({}, Vector) vec.x = x or 0 vec.y = y or 0 return vec end -- Vector addition function Vector:__add(other) return Vector:new(self.x + other.x, self.y + other.y) end -- Vector subtraction function Vector:__sub(other) return Vector:new(self.x - other.x, self.y - other.y) end -- Calculate vector length function Vector:length() return math.sqrt(self.x^2 + self.y^2) end -- Usage example local v1 = Vector:new(3, 4) local v2 = Vector:new(1, 2) local v3 = v1 + v2 print("Sum Vector:", v3.x, v3.y) -- 4, 6 print("Length of Vector 1:", v1:length()) -- 5 Metatables control the operations listed next. Each operation is identified by its corresponding name. The key for each operation is a string with its name prefixed by two underscores, '__'; for instance, the key for operation "add" is the string "__add". The semantics of these operations is better explained by a Lua function describing how the interpreter executes the operation. add": the + operation. The function getbinhandler below defines how Lua chooses a handler for a binary operation. First, Lua tries the first operand. If its type does not define a handler for the operation, then Lua tries the second operand. function getbinhandler (op1, op2, event) return metatable(op1)[event] or metatable(op2)[event] end By using this function, the behavior of the op1 + op2 is function add_event (op1, op2) local o1, o2 = tonumber(op1), tonumber(op2) if o1 and o2 then -- both operands are numeric? return o1 + o2 -- '+' here is the primitive 'add' else -- at least one of the operands is not numeric local h = getbinhandler(op1, op2, "__add") if h then -- call the handler with both operands return (h(op1, op2)) else -- no handler available: default behavior error(···) end end end "sub": the - operation. Behavior similar to the "add" operation. "mul": the * operation. Behavior similar to the "add" operation. "div": the / operation. Behavior similar to the "add" operation. "mod": the % operation. Behavior similar to the "add" operation, with the operation o1 - floor(o1/o2)*o2 as the primitive operation. "pow": the ^ (exponentiation) operation. Behavior similar to the "add" operation, with the function pow (from the C math library) as the primitive operation. "unm": the unary - operation. function unm_event (op) local o = tonumber(op) if o then -- operand is numeric? return -o -- '-' here is the primitive 'unm' else -- the operand is not numeric. -- Try to get a handler from the operand local h = metatable(op).__unm if h then -- call the handler with the operand return (h(op)) else -- no handler available: default behavior error(···) end end end "concat": the .. (concatenation) operation. function concat_event (op1, op2) if (type(op1) == "string" or type(op1) == "number") and (type(op2) == "string" or type(op2) == "number") then return op1 .. op2 -- primitive string concatenation else local h = getbinhandler(op1, op2, "__concat") if h then return (h(op1, op2)) else error(···) end end end "newindex": The indexing assignment table[key] = value. function settable_event (table, key, value) local h if type(table) == "table" then local v = rawget(table, key) if v ~= nil then rawset(table, key, value); return end h = metatable(table).__newindex if h == nil then rawset(table, key, value); return end else h = metatable(table).__newindex if h == nil then error(···) end end if type(h) == "function" then h(table, key,value) -- call the handler else h[key] = value -- or repeat operation on it end end "call": called when Lua calls a value. function function_event (func, ...) if type(func) == "function" then return func(...) -- primitive call else local h = metatable(func).__call if h then return h(func, ...) else error(···) end end end Override and Inheritance We can achieve inheritance using metatables in Lua. By creating subclasses and using the superclass's metatable, we can override some functions. -- 2D Vector Metatable Vector2D = setmetatable({}, Vector) Vector2D.__index = Vector2D -- Create a new 2D vector function Vector2D:new(x, y) local vec = Vector:new(x, y) setmetatable(vec, Vector2D) return vec end -- Rotate the 2D vector function Vector2D:rotate(angle) local cosA = math.cos(angle) local sinA = math.sin(angle) local newX = self.x * cosA - self.y * sinA local newY = self.x * sinA + self.y * cosA return Vector2D:new(newX, newY) end -- Usage example local v2d = Vector2D:new(1, 0) local v2dRotated = v2d:rotate(math.pi / 2) print("Rotated Vector:", v2dRotated.x, v2dRotated.y) -- 0, 1 More Complex scripts Metatables can be used to model complex data structures and behaviors. For example, we can create a class representing the attributes of a game character. -- Character metatable Character = {} Character.__index = Character function Character:new(name, health, power) local char = setmetatable({}, Character) char.name = name or "Unknown" char.health = health or 100 char.power = power or 10 return char end function Character:attack(target) target.health = target.health - self.power print(self.name .. " attacked " .. target.name .. "!") end -- Usage example local hero = Character:new("Hero", 150, 20) local monster = Character:new("Monster", 80, 15) hero:attack(monster) print(monster.name .. " remaining health: " .. monster.health) -- 60 NOT : Metatables form one of the foundations of object-oriented programming in Lua, allowing you to create complex structures and functionalities. In this guide, you learned how to create classes using metatables, inherit from them, and perform operator overloading. Metamethods: metatables and metamethods offer powerful functionality that enhances the flexibility and behavior of tables. Metatables allow you to customize the behavior of tables, while metamethods are functions that define this behavior. This tutorial will explore the fundamentals of these concepts with fun and practical examples,Metamethods are special functions defined within a metatable that get triggered when specific operations occur. Credits and Additional Resources Official Lua Documentation; Explore the official Lua documentation for comprehensive details on Lua features, including metatables. https://www.lua.org/manual/5.4/manual.html#2.4 https://www.lua.org/manual/5.1/manual.html#2.8 Lua 5.1 Reference Manual Lua 5.4 Reference Manual Metatable Events https://devdocs.io/lua~5.1/1 point
-
Ayy I used to work on MTA wayyyyy back when it started and everyone was figuring it out. With all the reverse-engineering and hacking, coding etc it was actually a bit of an adventure. I started working on a multiplayer GTA myself because I wanted it so bad (ill equipped but determined), and ended up joining with some of the early team. Really proud of everyone getting it together and keeping it going. I remember when we first got shooting working and we were all shooting each other outside that Vice City club that was the default spawn point for a while. I'll always remember the feeling of being the first people that ever played multiplayer GTA... wanting it so bad we manifested it. - Personally I just kept programming and doing random game dev stuff, I released a game made in Unreal Engine using the voxel plugin: https://store.steampowered.com/app/1079300/Goblin_Keep/ I felt incapable of supporting the game after release but I did it for the same reason at MTA, I just wanted to do it. Thanks to the team for keeping this going, who all did a lot more work on it than me1 point